Custom wp_Query-我得到的是‘all’帖子,而不是查询中的特定帖子

时间:2014-06-19 作者:user12920

从今天开始获取所有帖子,这些帖子类型为“product”,在“productType”分类法中为“Indica”,在“locationCity”分类法中为“Los Angeles”——然而,我获取的帖子“all”与自定义分类法的查询参数无关。

// args
$today = getdate();

$indicaArgs = array( 
        \'post_type\' => \'product\',
        \'productType\' => \'Indica\', 
        \'locationCity\' => \'Los Angeles\',
        \'posts_per_page\' => -1, 
        \'post_status\' => \'publish\',
        \'date_query\' => array(
                            array(
                                \'year\'  => $today["year"],
                                \'month\' => $today["mon"],
                                \'day\'   => $today["mday"],
                            ),  
                        )
);
// The Query
$query1 = new WP_Query($indicaArgs);

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

您应该使用tax_query 为此。见官方文件here.

尝试以下操作:

$indicaArgs = array( 
        \'post_type\' => \'product\',
        \'productType\' => \'Indica\', 
        \'locationCity\' => \'Los Angeles\',
        \'posts_per_page\' => -1, 
        \'post_status\' => \'publish\',
        \'tax_query\' => array(
          \'relation\' => \'AND\',
            array(
              \'taxonomy\' => \'productType\',
              \'field\' => \'slug\',
              \'terms\' => \'indica\', // here should be slug
              ),
            array(
              \'taxonomy\' => \'locationCity\',
              \'field\' => \'slug\',
              \'terms\' => \'los-angeles\', // here should be slug
              ),
          ),
        \'date_query\' => array(
                            array(
                                \'year\'  => $today["year"],
                                \'month\' => $today["mon"],
                                \'day\'   => $today["mday"],
                            ),  
                        )
);

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register