By dean2020


2019-03-14 12:12:37 8 Comments

I created this SQL query to generate a list of posts (which I will use for a CSV Sheet)

SELECT p.ID, p.post_content, p.post_title, pm1.meta_value as 'Amazon.com', pm2.meta_value as 'Amazon.co.uk' 

FROM wp_posts p 

LEFT JOIN wp_postmeta pm1 ON p.ID = pm1.post_id AND pm1.meta_key = 'Amazon.com'
LEFT JOIN wp_postmeta pm2 ON p.ID = pm2.post_id AND pm2.meta_key = 'Amazon.co.uk' 

WHERE post_type = 'post' AND post_status = 'publish'

I'm trying to accomplish the same using WP-CLI, using 'wp list' and such, but I haven't been able to find a way list all posts with their meta fields in one row.

How can I accomplish this using WP-CLI ?

1 comments

@dean2020 2019-03-14 12:19:48

Just figured it out. This isn't clearly or explicitly documented at https://developer.wordpress.org/cli/commands/post/list/ or elsewhere.

wp  post list --fields=ID,post_title,Amazon.com,Amazon.co.uk --meta_key=Amazon.com --meta_key=Amazon.co.uk

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] How to display multiple Post meta_key/meta_values by SQL query

2 Answered Questions

[SOLVED] Export WordPress Posts and Meta Information in CSV format

  • 2012-10-10 18:37:25
  • SixfootJames
  • 4738 View
  • 5 Score
  • 2 Answer
  • Tags:   posts post-meta sql

1 Answered Questions

[SOLVED] Find latest/published version of post using wp-cli

  • 2017-12-06 02:34:56
  • barrycarter
  • 101 View
  • 0 Score
  • 1 Answer
  • Tags:   wp-cli

1 Answered Questions

How do I extract the contents of a CPT's custom field for all posts?

1 Answered Questions

[SOLVED] Order posts by date and then by custom field

1 Answered Questions

[SOLVED] Only display posts that are in multidimensional meta_value

  • 2012-12-13 15:28:02
  • Pontus Abrahamsson
  • 280 View
  • 0 Score
  • 1 Answer
  • Tags:   wp-query

1 Answered Questions

[SOLVED] MySQL Query To Select Post By Postmeta

Sponsored Content