Ticket #15846 (reopened enhancement)

Opened 18 months ago

Last modified 17 months ago

Posts list associated to a term_taxonomy_id

Reported by: _DorsVenabili Owned by:
Priority: normal Milestone: Future Release
Component: Taxonomy Version: 3.1
Severity: normal Keywords: needs-docs
Cc: raven@…

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;

}

Change History

  • Summary changed from Posts list associated to a term_id to Posts list associated to a term_taxonomy_id
  • Milestone changed from Awaiting Review to Future Release

'term_taxonomy_id' is different from 'term_id'.

  • Status changed from new to closed
  • Resolution set to wontfix
  • Milestone Future Release deleted

Going to close as worksforme because you can already use get_posts() to retrieve the list of posts associated to certain term and then you can use the loop like you did to display them however you want.

  • Cc raven@… added
  • Keywords needs-docs added; term posts list associated removed
  • Status changed from closed to reopened
  • Resolution wontfix deleted
  • Type changed from enhancement to task (blessed)

Then I think get_posts() needs a review and must be marked as needs-docs.

 get_posts() have no documentation about it. I have not found how to get the posts of a taxonomy. I have used for this is get_objects_in_term(), still not documented.

comment:4 follow-up: ↓ 7   scribu18 months ago

  • Type changed from task (blessed) to enhancement
  • Milestone set to Future Release

Please do not mark tickets as blessed tasks unless you're a lead developer.

get_posts() is just a wrapper for WP_Query. See Otto's post:

 http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/

Normally we would update the codex, except it's scheduled for demise.

Sorry about that.

Thanks for the documentation.

Normally we would update the codex, except it's scheduled for demise.

This is a potential long-term goal that will occur in phases, and may not result in it completely disappearing.

In short, I wouldn't discourage Codex edits. It isn't going anywhere for some time and will still need to be updated, across the board, for 3.1 API changes and additions.

comment:7 in reply to: ↑ 4 ; follow-up: ↓ 8   SergeyBiryukov18 months ago

Replying to scribu:

Normally we would update the codex, except it's scheduled for demise.

Where can I get more info about that?

comment:8 in reply to: ↑ 7   SergeyBiryukov17 months ago

Replying to SergeyBiryukov:

Where can I get more info about that?

For the record: I've found out that Codex may be eventually transformed into curated handbooks:  http://lists.automattic.com/pipermail/wp-docs/2009-January/001862.html
 http://lists.automattic.com/pipermail/wp-docs/2009-August/002034.html
That actually makes sense and answers my question.

Note: See TracTickets for help on using tickets.