How can I use wp_get_object_terms() to get a list of all the terms attached to all posts in the current query?
For example, for the current query I want to get an array of the terms from the "Alfa" taxonomy that are contained in all the queried posts.
wp_get_object_terms($wp_query, 'alfa');
But that only seems to be returning one item in the array...
I am doing this to build an array to cross check one taxonomy with another for a navigation menu, and am currently doing this with the following code but I think there must be a better way.
Please help! Thanks!
$queried_terms = array();
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
$postid = $post->ID;
if( has_term( '', 'alfa', $postid) ) {
$terms = get_the_terms( $postid, 'alfa' );
foreach($terms as $term) {
$queried_terms[] = $term->slug;
}
}
endwhile; endif;
rewind_posts();
wp_reset_query();
$queried_terms = array_unique($queried_terms);
$wp_queryobject to the function? I guess that is not correct. – Rutwick Gangurde Apr 26 '12 at 5:10