Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks,

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

1 Answer

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.

<?php
$post_ID = 7;
$the_post = get_post( $post_ID );
$the_category = get_the_category( $post_ID );
share|improve this answer
add comment

Your Answer

 
discard

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.