WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to query the wordpress database for the post and what category they belong in. Is there a sql query that I can use for this?


share|improve this question
Are you trying to do this inside of WordPress or outside of it? – Joseph Oct 30 '12 at 0:11

To get a specific post in WordPress, you can use the get_post() function and get_the_category() to get the categories associated with it. You can then use the code found in this answer to dump the SQL queries used.

$post_ID = 7;
$the_post = get_post( $post_ID );
$the_category = get_the_category( $post_ID );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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