Trying to export the following data from WordPress or directory through MYSQL query.

Post ID | Post Title | Post Content | Post Excerpt | Post Primary Category | Primary Category Term ID | Post categories | Category Term IDs

I have close to 115k posts in the database and close to 20k categories. Each post has multiple categories. So that's why I want one column to only have the primary category and the other column to list call categories.

I have tried all of the export plugins and the problem I run into is that I can not export "Primary Category Term ID" all in one file. I can get all the other fields, expect for category ID in the same file...I can do it seperatly, but I am trying to get it all in one file. It will save a lot of time.

I think the only way is to write a custom query that can export all the fields I need directly from mysql? is anyone here able to help me accomplish this?

  • 1
    How are you storing primary category? That's not something WordPress does on its own.
    – Milo
    Feb 24, 2019 at 23:49
  • Is "Post Primary Category" a custom taxonomy? Feb 25, 2019 at 13:44

1 Answer 1


Actually there is no primary category key. Usually, the first category is primary category by default. So technically, the below are the only fields I will need.

Post ID | Post Title | Post Content | Post Excerpt | Post categories | Category Term IDs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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