Filter WP_Query for posts having a certain meta-value

How to filter WP_Query for posts having a certain meta-value, without using a Custom Select Query?

I have a custom posttype with meta-key: “open”, and meta-value options: “yes” or “no”.

Read More

I would like to show posts only with meta_value = yes, for meta_key = “open”.

function filter_where($where = '') {    

    $open = "yes";

    //$where .= " AND post_date > '" . date('Y-m-d', strtotime('-2 days')) . "'";
    return $where;
}
add_filter('posts_where', 'filter_where');

Related posts

Leave a Reply

2 comments

  1.  $querystr = "
        SELECT wposts.* 
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id 
        AND wpostmeta.meta_key = 'custom-key' 
        AND wposts.post_type = 'page' 
        ORDER BY wpostmeta.meta_value DESC
        ";