admin管理员组文章数量:1312758
I'm using this code which works really fine to list quite everything I need as Featured image and title, from my custom posts "portfolio".
<?php
$args = array(
'posts_per_page' => 5000,
'offset' => 0,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'portfolio',
'post_status' => 'publish',
'suppress_filters' => true );
$posts = get_posts($args);
foreach ($posts as $post) :
?>
<div class="grid-item">
<a href="<?php the_permalink();?>">
<div class="grid-image <?php echo get_the_category()?>">
<h2 class="grid-title"><?php echo the_title();?></h2>
<?php echo the_post_thumbnail(array(360,360));?>
</div>
</a>
</div>
But now, I'd like to list only posts from a choosen category. I tried to add these following terms in args but nothing seems to work.
'category' => 'category-slug',
'category' => category-id,
Any advice on this ? Many Thanks
I'm using this code which works really fine to list quite everything I need as Featured image and title, from my custom posts "portfolio".
<?php
$args = array(
'posts_per_page' => 5000,
'offset' => 0,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'portfolio',
'post_status' => 'publish',
'suppress_filters' => true );
$posts = get_posts($args);
foreach ($posts as $post) :
?>
<div class="grid-item">
<a href="<?php the_permalink();?>">
<div class="grid-image <?php echo get_the_category()?>">
<h2 class="grid-title"><?php echo the_title();?></h2>
<?php echo the_post_thumbnail(array(360,360));?>
</div>
</a>
</div>
But now, I'd like to list only posts from a choosen category. I tried to add these following terms in args but nothing seems to work.
'category' => 'category-slug',
'category' => category-id,
Any advice on this ? Many Thanks
Share Improve this question asked Dec 17, 2020 at 22:15 Alexandre TourretAlexandre Tourret 1 2 |1 Answer
Reset to default 1This is my loop, try using it.
<!-- Post -->
<?php
$paged= (get_query_var('paged' )) ? get_query_var('paged'):1;
global $query_string;
$myquery = wp_parse_args($query_string);
$myquery = array(
'paged' => $paged,
'posts_per_page'=>6,
'post_type' => 'portfolio'.
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'category',
'terms' => array('picture'),
'field' => 'slug',
),
),
);
query_posts($myquery);
while ( have_posts() ) : the_post();
?>
本文标签: categoriesHow to loop custom posttype from (a) specific category(ies)
版权声明:本文标题:categories - How to loop custom post_type from (a) specific category(ies)? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741908680a2404307.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
category
parameter is for the defaultcategory
taxonomy, so does your custom post type support that taxonomy? – Sally CJ Commented Dec 17, 2020 at 23:29