Support » Fixing WordPress » query_posts not working as expected

  • I have this line of code, which I expect to get every post with the custom field “page_views” set, sorted in desceding order. However, it finds no posts, despite the posts having that custom field set.

    query_posts( array('posts_per_page' => 1000,'order' => 'DESC', 'orderby' => 'meta_value_num', 'meta_key' => 'page_views' ) ) ;

    If I just use the query like this:

    query_posts( array('posts_per_page' => 1000 ) ) ;

    It gets the posts with no problem. What is wrong with the first query?

Viewing 2 replies - 1 through 2 (of 2 total)
  • What happens if you just use the meta_key?

    query_posts( array('posts_per_page' => 1000, 'meta_key' => 'page_views' ) ) ;

    If this does not work, perhaps the key is spelled incorrectly.

    Hi dibbit

    Can you got any solution. I am facing this kind of issue. Please share your solution.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts not working as expected’ is closed to new replies.