I have an array of ids that correspond to terms. How do I get the full term objects for each id?
$ids = array(1,2,3);
Ideally, I would love to be able to do something similar to the way taxonomy queries with WP_Query
work, but obviously with terms instead of posts.
I wonder if you mean something like this modified Codex example:
// Fetch:
$terms = get_terms( 'category', array(
'include' => array( 1, 2, 3 ),
) );
// Output:
if ( ! empty( $terms ) && ! is_wp_error( $terms ) )
{
$li = '';
foreach ( $terms as $term )
{
$li .= sprintf( "<li>%s</li>", $term->name );
}
printf( "<ul>%s</ul>", $li );
}
where $terms
contains an array of term objects, empty array or the WP_Error()
object.
Check the Codex on get_terms()
to get more information on the output and the input arguments. There you can get more code examples.