簡體   English   中英

WordPress按category_name獲取帖子不起作用

[英]WordPress get posts by category_name is not working

我需要按類別列出帖子順序。 我的顯示出現問題按類別的帖子沒有人為我工作,例如“ Category_name,tag_id,cat等”。

$args1 = array(
    'taxonomy'=> 'portfolio_cat',
    'orderby' => 'slug',
    'order'   => 'ASC',
);

$cats = get_categories($args1);
foreach ($cats as $cat) 
{
  //echo $cat->slug;
  $args2 = array(
  'post_type' => 'advanced_portfolio',
  'posts_per_page' => -1,
   //'tag_id' => 25,
   // 'category_name' =>$cat->slug,
   'category_name' =>'video' //my category name **slug**
   );

   query_posts($args2);
   if (have_posts()) : 
   while (have_posts()) : the_post(); 
   the_title();
   endwhile;

   endif; 
}

您使用的是自定義帖子類型,這意味着它不會包含常規類別,但會具有用作類別的分類法,這意味着您需要使用稅款查詢,還需要檢查條款,而不是經過測試,但應該可以工作:

$taxonomy = 'portfolio_cat';
$cats = get_terms($taxonomy);

foreach ($cats as $cat) {
  $args1 = array(
    'post_type' => 'advanced_portfolio',
    'posts_per_page' => -1,
    'tax_query' => array(
      array(
        'taxonomy' => 'portfolio_cat',
        'field'    => 'slug',
        'terms'    => 'video'
      ),
    ),
  );

  query_posts($args1);

  if (have_posts()) : 
    while (have_posts()) : the_post(); 
      the_title();
    endwhile;
  endif;
}
wp_reset_query();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM