Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用WordPress显示与特定分类相关的自定义文章类型_Php_Wordpress - Fatal编程技术网

Php 如何使用WordPress显示与特定分类相关的自定义文章类型

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 =

我试图在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 = 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 );
?>