How do I extract the contents of a CPT’s custom field for all posts?
-
I need to generate a CSV report with information that is stored into a few custom fields of a CPT.
I’m trying to use wp-cli to achieve this, because it’s an extremely powerful and versatile tool that never failed me before. Sorry if I’m approaching it as an “X-Y problem“!
Is there a wp-cli command that will list me just the content of these custom fields, for all (or a subset) of these CPTs?
For now all I got is
wp post list --post_type=<MYCPT> --posts_per_page=1
to get me the most recent post, and then
wp post meta list <ID>
with the ID returned in the previous command.
This lists me all the custom fields for a single custom post. What I need, however, is the content of just a few custom fields, for all custom posts of this type.
I suppose I can write a bash script to iterate through everything and grep just the custom fields I want, but is there an easier way?
- The topic ‘How do I extract the contents of a CPT’s custom field for all posts?’ is closed to new replies.