get_objects_in_term()

This WordPress function requires the CPT-onomy class.

Description

Retrieve the IDs of the objects who are tied to a valid CPT-onomy and term.

Usage

$cpt_onomy->get_objects_in_term( 						int|array
						$term_ids
						, 						string|array
						$cpt_onomies
						, 						string|array
						$args
						 );

Parameters

$term_ids (integer|array) (required)
Default: none
Term id or array of term ids of terms that will be used.

$cpt_onomies (string|array) (required)
Default: none
String of CPT-onomy name or Array of string values of CPT-onomy names.

$args (string|array) (optional)
Default: none
Change the order of the object_ids, either ASC or DESC.
For information on how to customize the $args parameter, refer to the WordPress codex.

Return Values

(array|WP_Error) If the CPT-onomy does not exist, then WP_Error will be returned. On success the array can be empty meaning that there are no $object_ids found or it will return the $object_ids found.

Examples

Note: You can also use a taxonomy query with the Loop to achieve the same results.

<?php

$objects = $cpt_onomy->get_objects_in_term( get_the_id(), 'actors' );

$args = array(
   'post_type' => 'movies',
   'post__in' => $objects,
   'orderby' => 'title',
   'order' => 'ASC',
);

query_posts( $args );
if ( have_posts() ) :
   ?><ul><?php
      while ( have_posts() ) : the_post();
         ?><li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li><?php
      endwhile;
   ?></ul><?php
endif;

<?php

Notes

  • Since 1.0.2

WordPress Codex

For more information, refer to the WordPress codex.