元查询关系“与”不起作用

时间:2021-02-03 作者:omid chahardoli

我想在库存中显示(特色产品),但此查询只显示库存产品。

$query = array(
        \'post_type\' => \'product\',
        \'post_status\' => \'publish\',
        \'posts_per_page\' => 12,
        \'orderby\' => \'date\',
        \'order\' => \'DESC\',
        \'meta_query\' => array(
          \'relation\' => \'AND\',
          array(
            \'key\' => \'_stock_status\',
            \'value\' => \'instock\',
          ),
          array(
              \'taxonomy\' => \'product_visibility\',
              \'field\' => \'name\',
              \'terms\' => \'featured\',
          ),
        ),
    );

1 个回复
最合适的回答,由SO网友:Buttered_Toast 整理而成

您混合了元查询和税务查询

应该是这样的

$query = array(
    \'post_type\' => \'product\',
    \'post_status\' => \'publish\',
    \'posts_per_page\' => 12,
    \'orderby\' => \'date\',
    \'order\' => \'DESC\',
    \'meta_query\' => array(
      array(
        \'key\' => \'_stock_status\',
        \'value\' => \'instock\'
      )
    ),
    \'tax_query\' => array(
      array(
          \'taxonomy\' => \'product_visibility\',
          \'field\' => \'name\',
          \'terms\' => \'featured\'
      )
    )
);

相关推荐

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

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