Php 如何显示自定义post';在没有链接和回显的循环中选择了什么自定义分类法?
下面是我试图整理的代码片段:Php 如何显示自定义post';在没有链接和回显的循环中选择了什么自定义分类法?,php,wordpress,custom-taxonomy,Php,Wordpress,Custom Taxonomy,下面是我试图整理的代码片段: $args=array( 'post_type' => 'custom_post_type', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_key' => 'custom_meta_key', 'meta_value' => 'on', ); $my_query
$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;
然而,这也引起了共鸣
<a rel="tag" href="http://myweb/custom_taxonomy/selectedTerm/">selectedTerm</a>
但我只需要selectedTerm
使用
strip\u tags()
没有帮助,因为术语()
正在回显链接。您将希望使用获取术语($post->ID,'custom\u taxonomy')
而不是术语()
这将返回一个术语对象数组。您可以通过执行以下操作访问术语名称:
while ( $my_query->have_posts() ) : $my_query->the_post();
$custom_taxonomy = the_terms( $post->ID, 'custom_taxonomy');
endwhile;
// Print the term names
foreach ( $custom_taxonomy as $term ) {
echo $term->name;
}
查看法典以了解更多关于的信息,我只是通过核心进行了歌舞表演,并发现了这一点。但是我必须使用
$custom\u taxonomy=array\u shift($custom\u taxonomy)代码>没有foreach循环,因为我一次只使用一个分类法