[wp-trac] [WordPress Trac] #15846: Posts list associated to a term_taxonomy_id
WordPress Trac
noreply at wordpress.org
Mon Aug 12 04:49:45 UTC 2013
#15846: Posts list associated to a term_taxonomy_id
---------------------------+-----------------------------
Reporter: _DorsVenabili | Owner:
Type: enhancement | Status: reopened
Priority: normal | Milestone: Future Release
Component: Taxonomy | Version: 3.1
Severity: normal | Resolution:
Keywords: needs-docs |
---------------------------+-----------------------------
Description changed by wonderboymusic:
Old description:
> 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;
> }
New description:
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#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list