Hello I have to export a wordpress database to csv, only certain fields are relevant, so I’m trying to construct a query in order to accomplish that goal.

Here are the tables from which I must collect data to export.
Tables needed to collect data from. Checked fields are needed

My output must be a csv file with the following structure

_posts.ID | _posts.post_title | _posts.post_content | _posts.post_date | _terms.name | _postmeta.meta_value (WHERE meta_key=’_wp_attached_file’)

_postmeta table includes several values related to each post, but I only need to get meta_value when meta_key is _wp_attached_file and that is the point where i’m sinking

My actual SQL sentence is:

SELECT _posts.ID, 
_posts.post_date, 
_posts.post_content, 
_posts.post_title, 
_postmeta.meta_value, 
_postmeta.meta_key, 
_postmeta.post_id
_terms.name, 
FROM _posts LEFT OUTER JOIN _term_relationships ON _posts.ID = _term_relationships.object_id
 LEFT OUTER JOIN _terms ON _terms.term_id = _term_relationships.term_taxonomy_id
 INNER JOIN _postmeta ON _postmeta.post_id = _posts.ID

WHERE _posts.post_status = ‘publish’ AND _posts.post_type = ‘post’

It returns redundant information because the content of _postmeta, so I need to filter the recordset by _postmeta.meta_key = '_wp_attached_file'

Any help will be appreciated.

Read more here: SQL sentence to collect all data and metadata related to wordpress post


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , , , ,

Wordpress related questions and answers: