Custom database query selecting posts of one category
-
I’m trying to create a database query which selects posts of a certain category and displays their titles and link. I’ve got everything working except the category selection feature. It seems that all the posts, regardless of what category they are in, show up with a post_category of 0 in the posts database. How can I select posts of a certain category? The code I’m using is below.
Thanks,
Joe<?php global $posts; if ( $post= $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type='post' AND post_category=6 ORDER BY post_date_gmt DESC LIMIT 5") ) : ?> <ul class="list-cat"> <?php foreach ($post as $pst) { echo '<li><a href="'.$pst->guid.'">'.$pst->post_title.'</a></li>'; } ?> </ul> <?php endif; ?>
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Custom database query selecting posts of one category’ is closed to new replies.