• 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)
  • ‘wp_terms.name’ ?

    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

    (@mjaffer)

    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

    (@mjaffer)

    Hi Chinmoy

    I saw your changes. It worked. Fantastic & thank you very much.

    Thread Starter mjaffer

    (@mjaffer)

    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

    try this

    new WP_Query(array(
    'post__not_in' => $do_not_duplicate
    ));

    hope it will work.

    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

    (@mjaffer)

    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.