Tax query is not working!

时间:2018-03-26 作者:Sujit Marcus
    $

        $arg =  array(
            \'post_type\' => \'plusnagarmitra\',
            \'posts_per_page\' => \'10\',


            \'tax_query\' => array(array(
                \'taxonomy\' => category,

                \'terms\' => 14

              ) ),

            \'post_status\' => array(
                \'publish\',
                \'pending\',
                \'draft\',
                \'private\',

            )
        ) ;

        $loop = new WP_QUERY($arg);
            ?>
        <div id="users">
                          <input class="search" placeholder="Search" />
                          <button class="sort" data-sort="name">
                            Sort by name
                          </button>
                           <button class="sort" data-sort="mobile">
                            Sort by Mobile
                          </button>

            <table id="postTable" >
            <thead>
              <tr>
               <th>Name</th><th>ID</th><th>Mobile</th><th>Address</th><th>SEX</th>
              </tr>
            </thead>

<tbody class="list">
            <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>



        <tr>
            <td class="name"><?php the_title( \'<p class="entry-title"><a href="\' . get_permalink() . \'" title="\' . the_title_attribute( \'echo=0\' ) . \'" rel="bookmark">\', \'</a></p>\' ); ?></td>



            <td class"ID"><?php echo get_field(\'nm_id\'); ?></td>



            <td class="mobile"><?php echo  get_field(\'durbash_mobile_no\'); ?></td>


            <td class="address"><?php echo  get_field(\'stayi_pata\'); ?></td>



            <td class="sex"><?php echo  get_field(\'ling\'); ?></td>

            <td><?php echo get_post_status( get_the_ID() ) ?></td>

            <td class="sex"> <a href="<?php the_permalink()?>">✍ EDIT</a> </td>



        </tr>

            <?php endwhile; ?>
</tbody>
            </tbody>

        </table>
$
1 个回复
SO网友:Jacob Peattie

您缺少引号category 作为查询中的分类:

\'taxonomy\' => category,
需要是

\'taxonomy\' => \'category\',
因此,分类查询如下所示

\'tax_query\' => array(
    array(
        \'taxonomy\' => \'category\',
        \'terms\'    => 14
    )
),

结束

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post