wp query - WP-CLI How to generate a list of posts with corresponding meta values

admin2025-06-02  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', 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'
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 ?

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', 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'
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 ?

Share Improve this question asked Mar 14, 2019 at 12:12 dean2020dean2020 2512 silver badges6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 11

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

wp  post list --fields=ID,post_title,Amazon,Amazon.co.uk --meta_key=Amazon --meta_key=Amazon.co.uk
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748806629a313877.html

最新回复(0)