Here’s the code snippet that I am trying to sort out:
$args=array(
'post_type' => 'custom_post_type',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'custom_meta_key',
'meta_value' => 'on',
);
$my_query = null;
$my_query = new WP_Query($args);
while ( $my_query->have_posts() ) : $my_query->the_post();
$custom_taxonomy = the_terms( $post->ID, 'custom_taxonomy');
endwhile;
however, this echoes
<a rel="tag" href="http://myweb/custom_taxonomy/selectedTerm/">selectedTerm</a>
but I only need the selectedTerm
Using strip_tags()
doesn’t help since the_terms()
is echoing the link.
You will want to use
get_the_terms( $post->ID, 'custom_taxonomy' )
instead ofthe_terms()
This will return an array of term objects. You can access the term names by doing the following:
Check out the codex for more information on get_the_terms()