首页 > 解决方案 > 分类的自定义查询

问题描述

我正在使用此查询来显示某些帖子。

query_posts( array(
                    'post_type' => APP_POST_TYPE,
                    'post_status' => 'publish',
                    'posts_per_page' => 4,
                    APP_TAX_STORE => $term->slug,
                    ),                      
                ) );

现在,我不想显示所有帖子,APP_TAX_STORE => $term->slug而是想排除它们。我尝试了以这种形式找到的所有解决方案,但没有任何效果。有任何想法吗?

标签: phpwordpressposts

解决方案


您可以使用tax_query.

query_posts( array(
  'post_type'      => APP_POST_TYPE,
  'post_status'    => 'publish',
  'posts_per_page' => 4,
  'tax_query'      => array(
    array(
      'taxonomy' => APP_TAX_STORE,
      'field'    => 'slug',
      'terms'    => $term->slug,
      'operator' => 'NOT IN',
    ),
  ),
) );

推荐阅读