[wp-trac] [WordPress Trac] #15846: Posts list associated to a term_id
WordPress Trac
wp-trac at lists.automattic.com
Thu Dec 16 15:38:55 UTC 2010
#15846: Posts list associated to a term_id
---------------------------+----------------------------------------
Reporter: _DorsVenabili | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 3.1
Severity: normal | Keywords: term posts list associated
---------------------------+----------------------------------------
It could be very useful to have in the core a function that retrieve the
list of all the posts associated to a term id. I have written the follow
one:
function posts_of_a_term_id($term_id, $limit){
global $wpdb;
$query = "SELECT object_id FROM $wpdb->term_relationships WHERE
term_taxonomy_id = $term_id ORDER BY object_id DESC LIMIT $limit";
$results = $wpdb->get_results($query);
foreach($results as $result):
$id = $result->object_id;
query_posts('p='.$id.'');
if ( have_posts() ) :
while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink();
?>"><?php the_title(); ?></a></li>
<?php endwhile;
endif;
wp_reset_query();
endforeach;
}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15846>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list