Is it possible to use the WordPress API (query_posts, WP_Query, get_posts etc) to fetch future posts based on a custom taxonomy?

I’m looking for a way to fetch posts in wordpress that are slated for future publication based on a custom taxonomy query. Finding future posts is
otherwise, simple

query_posts('post_status=future');

But adding a custom taxonomy doesn’t work as expected

Read More
query_posts('musicians=paul-mccartney&post_status=future'); 

I ended up using the $wpdb and writing the SQL by hand and joining the terms, taxonomy and relationships tables together.

$sql = "SELECT post.* 
  FROM {$wpdb->prefix}terms term 
  JOIN {$wpdb->prefix}term_taxonomy taxonomy
  JOIN {$wpdb->prefix}term_relationships relationship
  JOIN {$wpdb->prefix}posts post
  WHERE term.term_id = taxonomy.term_id
  AND relationship.term_taxonomy_id = taxonomy.term_taxonomy_id
  AND term.slug = '%s'
  AND taxonomy.taxonomy = '%s'
  AND post.ID = relationship.object_id";

if($posts = $wpdb->get_results( $wpdb->prepare($sql, $term->slug, $term->taxonomy) )):      
  foreach($posts as $post):
   setup_postdata($post);
     the_ID().' '.the_title().'n<br/>';
  endforeach;
endif;

This works but I’m hoping that there is a way to accomplish the same but using the WP API (query_posts, WP_Query, get_posts etc)!

Related posts

Leave a Reply

1 comment