• Some of my posts do have and some don’t have set price custom field. What i want to do is to show (in list) all posts that don’t have custom field price set.

Viewing 1 replies (of 1 total)
  • You will have to do a custom search query:
    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    they have an example that includes:
    <?php

    $querystr = “
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id
    AND wpostmeta.meta_key = ‘tag’
    AND wpostmeta.meta_value = ’email’
    AND wposts.post_status = ‘publish’
    AND wposts.post_type = ‘post’
    AND wposts.post_date < NOW()
    ORDER BY wposts.post_date DESC
    “;

    $pageposts = $wpdb->get_results($querystr, OBJECT);

    ?>

    and you just change it to:
    <?php

    $querystr = “
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id
    AND wpostmeta.meta_value = ”
    AND wposts.post_status = ‘publish’
    AND wposts.post_type = ‘post’
    AND wposts.post_date < NOW()
    ORDER BY wposts.post_date DESC
    “;

    $pageposts = $wpdb->get_results($querystr, OBJECT);

    ?>

    That should do it

Viewing 1 replies (of 1 total)
  • The topic ‘How to query_posts that don't have a meta_value set?’ is closed to new replies.