1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.