Php Can';在Wordpress中使用自定义帖子类型时,在循环中对类别进行t筛选

Php Can';在Wordpress中使用自定义帖子类型时,在循环中对类别进行t筛选,php,wordpress,Php,Wordpress,我尝试使用下面的代码显示来自名为portfolio的自定义帖子类型的帖子,然后按类别过滤结果,我尝试将-category\u name、catid、portfolio\u category放入数组中 我在论坛上浏览了一下,尝试了一些东西,但似乎无法使其发挥作用,它要么什么也不显示,要么显示所有类别的帖子 <?php $args=array( 'post_type' => 'portfolio', 'post_status' => 'publi

我尝试使用下面的代码显示来自名为portfolio的自定义帖子类型的帖子,然后按类别过滤结果,我尝试将-category\u name、catid、portfolio\u category放入数组中

我在论坛上浏览了一下,尝试了一些东西,但似乎无法使其发挥作用,它要么什么也不显示,要么显示所有类别的帖子

     <?php
     $args=array(
    'post_type' => 'portfolio',
    'post_status' => 'publish',
    'posts_per_page' => 7,
    'caller_get_posts'=> 1
     );
     $my_query = null;
     $my_query = new WP_Query($args);
     if( $my_query->have_posts() ) {
     while ($my_query->have_posts()) : $my_query->the_post(); ?>
     <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to 
     <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
     <?php
      endwhile;
      }
     wp_reset_query();  // Restore global post data stomped by the_post().
     ?>


注册的分类法是portfolio_分类法,如有任何帮助,我们将不胜感激,非常感谢

您可以尝试将该分类法称为自定义分类法:

'portfolio_cat' => 'name_of_your_category'

在尝试了一些事情之后,这就是我如何使用“tax_query”使其工作的原因,希望这对某人有所帮助

     <?php

     $args = array(
     'post_type'=>'portfolio',
  'tax_query' => array(
    array(
        'taxonomy' => 'portfolio_category',
        'field' => 'slug',
        'terms' => 'solutions'
    )
   )
       );
     $my_query = new WP_Query( $args );

     if( $my_query->have_posts() ) {
     while ($my_query->have_posts()) : $my_query->the_post(); ?>

     <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to 
     <?php the_title_attribute(); ?>">
     <?php the_title(); ?></a></p>
      <?php the_excerpt()?>
      <?php echo get_the_post_thumbnail($post->ID,  array(50,50)); ?> 
      <?php
      endwhile;
      }
     wp_reset_query();  // Restore global post data stomped by the_post().
     ?>


我就是这样让它工作的$args=array('post_-type'=>'portfolio','tax_-query'=>array(array('taxonomy'=>'portfolio_-category','field'=>'slug','terms'=>'solutions'))$my_query=新的WP_查询($args)@不客气。既然我的回答是对的,你本可以把它标为接受的。至少投赞成票。任何事都可以,但不能有负面的名声(