Make WordPress Core

Opened 5 years ago

Closed 2 years ago

#15846 closed enhancement (worksforme)

Posts list associated to a term_taxonomy_id

Reported by: _DorsVenabili Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Taxonomy Keywords:
Focuses: Cc:

Description (last modified by wonderboymusic)

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;
		if ( have_posts() ) : 
			while ( have_posts() ) : the_post(); ?>
				<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
			<?php endwhile;

Change History (10)

comment:1 @scribu5 years ago

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

'term_taxonomy_id' is different from 'term_id'.

comment:2 @scribu5 years ago

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

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.

comment:3 @bi0xid5 years ago

  • Cc raven@… added
  • Keywords needs-docs added; term posts list associated removed
  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • 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: @scribu5 years ago

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

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:


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

comment:5 @bi0xid5 years ago

Sorry about that.

Thanks for the documentation.

comment:6 @nacin5 years ago

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: @SergeyBiryukov5 years 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 @SergeyBiryukov5 years 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:
That actually makes sense and answers my question.

comment:9 @wonderboymusic2 years ago

  • Description modified (diff)

comment:10 @wonderboymusic2 years ago

  • Keywords needs-docs removed
  • Milestone Future Release deleted
  • Resolution set to worksforme
  • Status changed from reopened to closed

tax_query is now a thing that is documented and whatnot

Note: See TracTickets for help on using tickets.