Link to home
Start Free TrialLog in
Avatar of Chris Michalczuk
Chris MichalczukFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Wordpress need to extract into excel all posts that have a specific category ID

Hi I am trying to extract a list of post header info into an excel spreadsheet from WORDPRESS (using sql express php)
these are events so I need the start and end dates but cant see them in any tables?

I have managed to extract the categories using the following
SELECT *
FROM wp_term_relationships
LEFT JOIN wp_term_taxonomy
   ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
LEFT JOIN wp_terms on wp_term_taxonomy.term_taxonomy_id = wp_terms.term_id
WHERE wp_term_taxonomy.taxonomy = 'category'
GROUP BY wp_term_taxonomy.term_id

I now need the posts associated with TERM_Id =71

what code do I need to sort get this please
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here you can find whole database diagram with description.

https://codex.wordpress.org/Database_Description

I am using plugin for extractions

http://www.wpallimport.com/export/
Avatar of Chris Michalczuk

ASKER

I managed to sort the query as follows too
SELECT *,
(select meta_value from `wp_postmeta`  where post_id = posts.id and meta_key = '_EventStartDate') as StartDate,
(select meta_value from `wp_postmeta`  where post_id = posts.id and meta_key = '_EventEndDate') as EndDate
FROM
`wp_posts` as posts
LEFT JOIN wp_term_relationships term ON posts.ID = term.object_id
WHERE term.term_taxonomy_id =71
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think this will work and its full code