如何在WordPress查询帖子中传递meta_value

时间:2014-07-05 10:49:51

标签: php wordpress

我想在wordpress的查询帖子中传递meta_value。

我在这里尝试编码,但没有工作。

<?php
           $db_highest = $wpdb->get_results($wpdb->prepare("SELECT meta_value
FROM wp_postmeta
WHERE meta_key = 'rating_count'
ORDER BY `wp_postmeta`.`meta_value` DESC
LIMIT 0 , 1000")); 

  global $wp_query;

               query_posts(array(

                    'paged' => $wp_query->get('paged'),

                    'post_type' => array('company'),


                    'posts_per_page' => $opt_metrodir_company_list_count,

                    'meta_query' => array(

                      'meta_value' => $db_highest

            ));


           ?>

我想使用meta_value查询,所以我得到评级值计数的降序,如10,8,5,4,3,2,1 我想显示评分最高的帖子。 如果我print_r($ db_highest);然后它显示在结果下面。

Array
(
    [0] => stdClass Object
        (
            [meta_value] => 2
        )

    [1] => stdClass Object
        (
            [meta_value] => 2
        )

    [2] => stdClass Object
        (
            [meta_value] => 2
        )

    [3] => stdClass Object
        (
            [meta_value] => 2
        )

    [4] => stdClass Object
        (
            [meta_value] => 1
        )

    [5] => stdClass Object
        (
            [meta_value] => 1
        )

    [6] => stdClass Object
        (
            [meta_value] => 1
        )

    [7] => stdClass Object
        (
            [meta_value] => 1
        )

    [8] => stdClass Object
        (
            [meta_value] => 
        )

)

所以最后我的结果将是这样的

query_posts(array(

                    'paged' => $wp_query->get('paged'),

                    'post_type' => array('company'),


                    'posts_per_page' => $opt_metrodir_company_list_count,

                    'meta_query' => array(

                      'meta_value' => array(2,2,2,2,1,1,1,1)

                        ));

0 个答案:

没有答案