Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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
Wordpress 如何显示特定自定义帖子类型类别中的帖子_Wordpress - Fatal编程技术网

Wordpress 如何显示特定自定义帖子类型类别中的帖子

Wordpress 如何显示特定自定义帖子类型类别中的帖子,wordpress,Wordpress,我正试图显示一篇来自我在自定义文章类型中创建的类别的文章 这是我当前的循环代码 我想在公告帖子类型中显示奖项类别中的帖子 <?php $loop = new WP_Query( array( 'posts_per_page' => 99,'post_type' => 'annoucements','orderby' => 'date','order' => 'ASC','ignore_sticky_posts' => 1, 'paged' => $pag

我正试图显示一篇来自我在自定义文章类型中创建的类别的文章

这是我当前的循环代码

我想在公告帖子类型中显示奖项类别中的帖子

<?php $loop = new WP_Query( array( 'posts_per_page' => 99,'post_type' => 'annoucements','orderby' => 'date','order' => 'ASC','ignore_sticky_posts' => 1, 'paged' => $paged ) ); if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_title()?>                                                         
<?php endwhile; endif; wp_reset_postdata();?>   

如果你想从一个类别中获得帖子,那么你必须在
WP\u Query
参数中传递类别slug

$args = array(
    'posts_per_page' => 99,
    'post_type' => 'annoucements',
    'category_name' => 'awards', //<-- add this
    'orderby' => 'date',
    'order' => 'ASC',
    'ignore_sticky_posts' => 1,
    'paged' => $paged);
$loop = new WP_Query($args);
if ($loop->have_posts()) :
    while ($loop->have_posts()) : $loop->the_post();
        the_title();
    endwhile;
endif;
wp_reset_postdata();
$args=array(
“每页帖子数”=>99,
“发布类型”=>“公告”,
“类别名称”=>“奖项”/“日期”,
“订单”=>“ASC”,
“忽略粘性帖子”=>1,
“paged'=>paged美元);
$loop=新的WP_查询($args);
如果($loop->have_posts()):
而($loop->have_posts()):$loop->the_post();
_title();
结束时;
endif;
wp_reset_postdata();
参考:

希望这有帮助

您可以使用此代码显示来自特定自定义帖子类型的帖子 类别(分类法

根据广泛且长期运行的trac票证,自定义帖子类型不(也可能不会)支持粘性功能。

如果您发现此代码中存在任何问题,请告诉我。谢谢


<?php
    $options = array(
        'post_type' => 'annoucements',
        'posts_per_page' => 99,
        'orderby' => 'date',
        'order' => 'ASC',
        'paged' => $paged,
        'tax_query' => array(
            array(
                'taxonomy' => 'taxonomy_cat', // Here I have set dummy taxonomy name like "taxonomy_cat" but you must be set current taxonomy name of annoucements post type. 
                'field' => 'name',
                'terms' => 'awards'
            )
        )
    );
    $query = new WP_Query( $options );
    if ( $query->have_posts() ) :
        while($query->have_posts()) : $query->the_post();
            the_title();
        endwhile; wp_reset_query();
    endif;
    ?>