这个wp_Query有什么问题?

时间:2013-04-12 作者:Bryan White

我需要通过两个元字段查询帖子,而我使用的wo\\U查询没有返回任何内容。显然,它坏了。有人能告诉我我做错了什么吗?

$args = array(
                    \'post_type\' => \'espresso_event\',
                    \'post_status\' => \'publish\',
                    \'posts_per_page\' => 8,
                    \'category_name\' => \'homepage\',
                    \'meta_query\' => array(
                        array(
                            \'key\' => \'event_start_date\',
                            \'value\' => date(\'Y-m-d\'),
                            \'compare\' => \'>=\',
                            \'type\' => \'DATE\'
                            ),
                        array(
                            \'key\' => \'event_end_time\',
                            \'value\' => date(\'g:i A\'),
                            \'compare\' => \'>=\',
                            \'type\' => \'TIME\'
                            )
                        ),
                    \'orderby\' => \'meta_value\',
                    \'order\' => \'ASC\' // change this to ASC if you want newer events on top
                );
        // this saves the query to a temporary location so we can go back to it later after we run our query
        $temp = $wp_query;
        $wp_query = null;
        $wp_query = new WP_Query();
        $wp_query->query($args);
查询在没有此部分的情况下工作:

array(
                            \'key\' => \'event_end_time\',
                            \'value\' => date(\'g:i A\'),
                            \'compare\' => \'>=\',
                            \'type\' => \'TIME\'
                            )
很明显,问题就在那里,但我没有得到任何错误或任何东西,所以我看不出问题是什么。

1 个回复
SO网友:vancoder

您应该以24小时格式存储和比较时间:00:00:00。

array(
\'key\' => \'event_end_time\',
 \'value\' => date(\'G:i:s\'),
 \'compare\' => \'>=\',
 \'type\' => \'TIME\'
)

结束

相关推荐

WP_Query or get_posts?

使用“fields”=>“ids”参数时,在下面的代码中创建新的WP\\u查询是否比执行get\\u post更好?如果使用WP\\u查询,循环会是什么样子?function myplugin_delete_image_items( $postid ) { $args = array( \'post_type\' => \'myplugin_image_item\', \'cache_results\' =&g