Title: WP_Query
Last modified: August 19, 2016

---

# WP_Query

 *  [mjaffer](https://wordpress.org/support/users/mjaffer/)
 * (@mjaffer)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/)
 * I have he following query:
    $the_query = new WP_Query(array( ‘showposts’ => 1,‘
   post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘lead_item_order’,‘
   meta_value’ => ‘2’, ‘wp_terms.name’ => ‘News’ ));
 * I am a newbie to wordpress. Can someone please tell me why this does not return
   the correct post?
 * Any help will be appreciated.
 * Thanks

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536099)
 * ‘wp_terms.name’ ?
 *  [Chinmoy](https://wordpress.org/support/users/chinmoy/)
 * (@chinmoy)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536145)
 * Try this once:
 *     ```
       $the_query = new WP_Query(array(
       'showposts' => 1,
       'post_type' => 'post',
       'post_status' => 'publish',
       'meta_key' => 'lead_item_order',
       'meta_value' => '2',
       'category_name' => 'News'
       ));
       ```
   
 *  Thread Starter [mjaffer](https://wordpress.org/support/users/mjaffer/)
 * (@mjaffer)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536153)
 * Hi Chinmoy
 * I am trying to pass the Category Name as a parameter. I need to find all posts
   within the News category only.
 * I hope this helps.
 * Thanks
 *  Thread Starter [mjaffer](https://wordpress.org/support/users/mjaffer/)
 * (@mjaffer)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536154)
 * Hi Chinmoy
 * I saw your changes. It worked. Fantastic & thank you very much.
 *  Thread Starter [mjaffer](https://wordpress.org/support/users/mjaffer/)
 * (@mjaffer)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536157)
 * Hi Chinmoy
 * I now need to create a query where I want to ignore all posts which have a ‘meta_key’
   => ‘lead_item_order’
 * Thanks
 *  [Chinmoy](https://wordpress.org/support/users/chinmoy/)
 * (@chinmoy)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536158)
 * try this
 *     ```
       new WP_Query(array(
       'post__not_in' => $do_not_duplicate
       ));
       ```
   
 * hope it will work.
 *  [Chinmoy](https://wordpress.org/support/users/chinmoy/)
 * (@chinmoy)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536159)
 * Ignore my previous comment
 *     ```
       <?php
   
        $querystr = "
           SELECT wposts.*
           FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
           WHERE wposts.ID = wpostmeta.post_id
           AND wpostmeta.meta_key != 'lead_item_order'
           AND wpostmeta.meta_value != '2'
           AND wposts.post_status = 'publish'
           AND wposts.post_type = 'post'
           ORDER BY wposts.post_date DESC
        ";
   
        $pageposts = $wpdb->get_results($querystr, OBJECT);
   
        ?>
       ```
   
 * Try this code.
 *  Thread Starter [mjaffer](https://wordpress.org/support/users/mjaffer/)
 * (@mjaffer)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536178)
 * Hi Chinmoy
 * Thanks for this. However I need a query which will only return posts which do
   not have meta_key of ‘lead_item_order’. Your query will bring all posts because
   there are other meta_key values for these posts in wppostmeta.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘WP_Query’ is closed to new replies.

 * 8 replies
 * 3 participants
 * Last reply from: [mjaffer](https://wordpress.org/support/users/mjaffer/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/wp_query-3/#post-1536178)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
