Php 如何使用WordPress显示与特定分类相关的自定义文章类型
我试图在WP中显示特定分类法的所有自定义帖子类型 代码如下:Php 如何使用WordPress显示与特定分类相关的自定义文章类型,php,wordpress,Php,Wordpress,我试图在WP中显示特定分类法的所有自定义帖子类型 代码如下: <?php $args = array( 'post_type' => 'team', 'orderby' => 'rand', 'posts_per_page' => -1 ); $trit = new WP_Query($args); while ($trit->have_posts()) : $trit->the_post(); $post_id =
<?php
$args = array(
'post_type' => 'team',
'orderby' => 'rand',
'posts_per_page' => -1
);
$trit = new WP_Query($args);
while ($trit->have_posts()) : $trit->the_post();
$post_id = get_the_ID();//POST ID
$terms = get_the_terms($post->ID, 'tax_members' );
...
endwhile;
试试这个
试试这个嗨,谢谢你的脚本…我的问题是:如何将你的脚本与帖子类型id关联?我在这里感到困惑,请适当解释一下。我的目标是显示与特定分类相关的所有自定义帖子类型:玩家。抱歉…我的代码中有一个错误。您的脚本正在运行。ThanksHi,谢谢你的脚本…我的问题是:如何将你的脚本与帖子类型id关联?我在这里感到困惑,请适当解释一下。我的目标是显示与特定分类相关的所有自定义帖子类型:玩家。对不起…我的代码中有一个错误。您的脚本正在运行。谢谢
$terms = get_the_terms($post->ID, 'tax_members' );
$args = array(
'post_type' => 'team',
'orderby' => 'rand',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'tax_members',
'terms' => array('players'),
)
)
);
<?php
$queryArr = array(
'post_type' => 'team',
'orderby' => 'rand',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'tax_members',
'field' => 'slug',
'terms' => 'players',
'operator' => 'IN'
),
),
);
$trit = get_posts( $queryArr );
?>