0

下面是我写给 WP_Query 一堆过滤器的代码,这些过滤器涉及帖子的自定义元字段,

        <?php
            global $post;
            $month=date("m", time());    //current month
            $month=intval($month);       //converting '03' to int 3
            $args = array( 'meta_key'=>"city", 'meta_value'=>'NY',   'numberposts' => 100, 
'cat'=>"read", "monthnum" => $month, 'post_status' =>  "publish", 
'order'=>"ASC", "orderby" => "meta_value_num", "meta_key" => "article_order");      
            $posts = WP_Query( $args );
        ?>

我想从上面的查询中实现的是,“从 'read' 类别中选择本月发布的帖子,元键 'city' 的值为 'NY' 并按 meta_key 'article_order' 的 'meta_value_num' 排序”

4

1 回答 1

0

可能会尝试一些事情,比如

<?php
            global $post;
            $month=date("m", time());    //current month
            $month=intval($month);       //converting '03' to int 3
            $args = array( 'meta_query' => array(
        array(
            'key' => 'city',
            'compare' => '==',
            'value' => 'NY',
        )
    ), 'numberposts' => 100, 
'cat'=>"read", "monthnum" => $month, 'post_status' =>  "publish", 
'order'=>"ASC", "orderby" => "meta_value_num", "meta_key" => "article_order");      
            $posts = WP_Query( $args );
        ?>

希望这项工作以及在您的代码中您缺少 '' 在您的'meta_key'=>cityas'meta_key'=>'city'

希望这对你有用

于 2013-03-29T09:23:57.440 回答