Help Needed Retrieving Posts With SQL
-
I want to isolate certain posts within a category using a custom taxonomy (‘trans-front-001’ in this instance). Dealing with the category comes later, but first the following. The nested subquery works — it delivers the IDs of desired posts — but the SQL that wraps it that is meant to produce the posts themselves seems to yield nothing:
<?php $query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID = (SELECT object_id FROM wp_terms, wp_term_relationships WHERE wp_terms.term_id = wp_term_relationships.term_taxonomy_id AND wp_terms.slug='trans-front-001')"); $whichposts = $wpdb->get_results( $query, OBJECT ); ?>Or is the code to which I then deliver these posts a mismatch (working code that was cannibalized from elsehwere — reduced here for concision)):
<?php if ($whichposts): global $post; foreach ($whichposts as $post): setup_postdata($post); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> </div> <?php endforeach; ?> <?php endif; ?>
The topic ‘Help Needed Retrieving Posts With SQL’ is closed to new replies.