如何在wordpress中获取特定帖子类型的标签列表?

如何在wordpress中获取特定帖子类型的标签列表?,wordpress,wordpress-theming,custom-wordpress-pages,Wordpress,Wordpress Theming,Custom Wordpress Pages,我想打印我的特定帖子类型页面的标签列表。我使用了每个函数来获取标签。但是它给了我所有的标签列表,包括在其他帖子类型中使用的标签列表。用于创建小部件的过滤器类型。根据帖子类型获取标签列表时必须使用此选项 为此,我创建了一个通用函数,您可以根据帖子类型列出标签或任何分类列表 函数按发布类型获取发布类型($taxo\u term,$post\u types){ } 调用此函数并传递分类术语和post类型。它将为您提供一个标签数组。用于创建小部件的过滤器类型。根据帖子类型获取标签列表时必须使用此选项 &

我想打印我的特定帖子类型页面的标签列表。我使用了每个函数来获取标签。但是它给了我所有的标签列表,包括在其他帖子类型中使用的标签列表。

用于创建小部件的过滤器类型。根据帖子类型获取标签列表时必须使用此选项

为此,我创建了一个通用函数,您可以根据帖子类型列出标签或任何分类列表

函数按发布类型获取发布类型($taxo\u term,$post\u types){

}


调用此函数并传递分类术语和post类型。它将为您提供一个标签数组。

用于创建小部件的过滤器类型。根据帖子类型获取标签列表时必须使用此选项

<!-- begin custom related loop, isa -->

<?php 

// get the custom post type's taxonomy terms

$custom_taxterms = wp_get_object_terms( $post->ID, 'your_taxonomy', array('fields' => 'ids') );
// arguments
$args = array(
'post_type' => 'your_custom_post_type',
'post_status' => 'publish',
'posts_per_page' => 3, // you may edit this number
'orderby' => 'rand',
'tax_query' => array(
    array(
        'taxonomy' => 'your_taxonomy',
        'field' => 'id',
        'terms' => $custom_taxterms
    )
),
'post__not_in' => array ($post->ID),
);
$related_items = new WP_Query( $args );
// loop over query
if ($related_items->have_posts()) :
echo '<ul>';
while ( $related_items->have_posts() ) : $related_items->the_post();
?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
echo '</ul>';
endif;
// Reset Post Data
wp_reset_postdata();
?>
为此,我创建了一个通用函数,您可以根据帖子类型列出标签或任何分类列表

函数按发布类型获取发布类型($taxo\u term,$post\u types){

}

调用此函数并传递分类术语和post类型。它将为您提供一系列标记。


<!-- begin custom related loop, isa -->

<?php 

// get the custom post type's taxonomy terms

$custom_taxterms = wp_get_object_terms( $post->ID, 'your_taxonomy', array('fields' => 'ids') );
// arguments
$args = array(
'post_type' => 'your_custom_post_type',
'post_status' => 'publish',
'posts_per_page' => 3, // you may edit this number
'orderby' => 'rand',
'tax_query' => array(
    array(
        'taxonomy' => 'your_taxonomy',
        'field' => 'id',
        'terms' => $custom_taxterms
    )
),
'post__not_in' => array ($post->ID),
);
$related_items = new WP_Query( $args );
// loop over query
if ($related_items->have_posts()) :
echo '<ul>';
while ( $related_items->have_posts() ) : $related_items->the_post();
?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
echo '</ul>';
endif;
// Reset Post Data
wp_reset_postdata();
?>


我的问题是针对特定的职位类型。没有一个职位。因此,如果在wp_get_object_术语($post_id,'post_tag',$optional_args)中将您的post类型值作为post_标记值传递,则这对我的情况没有用处;你得到了结果。请参考@priya链接。你应该正确阅读文档。你给出的链接清楚地提到“post_tag”参数必须是一个分类法。你不能在那里传递帖子类型。我的问题是针对特定的帖子类型。没有一个职位。因此,如果在wp_get_object_术语($post_id,'post_tag',$optional_args)中将您的post类型值作为post_标记值传递,则这对我的情况没有用处;你得到了结果。请参考@priya链接。你应该正确阅读文档。你给出的链接清楚地提到“post_tag”参数必须是一个分类法。您不能在那里传递post type。