Wordpress 如何在wp post循环中打印术语名称?

Wordpress 如何在wp post循环中打印术语名称?,wordpress,Wordpress,我在一个自定义的帖子类型中有3种不同的分类法。我想打印所有的职位与任期名称与他们 例如: 分类法1=>分类法=银行和邮政类型=信用卡 分类法2=>taxonomy=joiningfees&post_type=信用卡 分类法3=>taxonomy=cardtype&post_type=信用卡 所以我想打印所有带有术语名称的自定义帖子 我可以通过输入单个分类法打印数据,但如何使用所有分类法术语打印数据 质疑 您可以使用get\u terms中的数组获取多个分类术语。将代码替换为以下内容: $args

我在一个自定义的帖子类型中有3种不同的分类法。我想打印所有的职位与任期名称与他们

例如: 分类法1=>分类法=银行和邮政类型=信用卡

分类法2=>taxonomy=joiningfees&post_type=信用卡

分类法3=>taxonomy=cardtype&post_type=信用卡

所以我想打印所有带有术语名称的自定义帖子 我可以通过输入单个分类法打印数据,但如何使用所有分类法术语打印数据

质疑


您可以使用
get\u terms
中的数组获取多个分类术语。将代码替换为以下内容:

$args = array('post_type' => 'creditcards',
    'posts_per_page' => -1
);

$loop = new WP_Query($args);

if ($loop->have_posts()) {

    while ($loop->have_posts()) : $loop->the_post();
        $custom_terms = wp_get_post_terms(get_the_ID(), array(
            'banks',
            'joiningfees',
            'cardtype'), array("fields" => "all"));

        $custom_term = wp_list_pluck($test, 'name'); //To get term name from term taxonomy array

        echo join(', ', $custom_term); //This will print all term name and remove ',' from last term name
        ?>
        <div>
            <strong>
                <?php echo the_title(); ?>
            </strong>
        </div>
        <?php
    endwhile;
}
$args=array('post_type'=>“信用卡”,
“每页帖子”=>-1
);
$loop=新的WP_查询($args);
如果($loop->have_posts()){
而($loop->have_posts()):$loop->the_post();
$custom_terms=wp_get_post_terms(获取_ID(),数组(
"银行",,
“联合费用”,
“cardtype”)、数组(“字段”=>“全部”);
$custom_term=wp_list_pull($test,'name');//从术语分类数组中获取术语名称
echo join(“,”,$custom_term);//这将打印所有术语名称,并从上一个术语名称中删除“,”
?>



我需要术语1、术语2、术语3
标题…但它在每行和每循环中打印单个术语..就像术语1、术语1、术语1
标题一样,你的意思是如果某个标题有多个术语,那么它将显示在单行中,然后中断,对吗?我用图像更新了问题。我希望根据loopOk中的CPT数据得到结果,所以我更新了我的代码用于获取包含所有分类术语的帖子。请尝试此代码一次

    taxonomy1 term,taxonomy2 term,taxonomy3 term
    the title

    taxonomy1 term,taxonomy2 term,taxonomy3 term
    the title

    taxonomy1 term,taxonomy2 term,taxonomy3 term
    the title
$args = array('post_type' => 'creditcards',
    'posts_per_page' => -1
);

$loop = new WP_Query($args);

if ($loop->have_posts()) {

    while ($loop->have_posts()) : $loop->the_post();
        $custom_terms = wp_get_post_terms(get_the_ID(), array(
            'banks',
            'joiningfees',
            'cardtype'), array("fields" => "all"));

        $custom_term = wp_list_pluck($test, 'name'); //To get term name from term taxonomy array

        echo join(', ', $custom_term); //This will print all term name and remove ',' from last term name
        ?>
        <div>
            <strong>
                <?php echo the_title(); ?>
            </strong>
        </div>
        <?php
    endwhile;
}