Leave a Reply

1 comment

  1. I think you can do a left join :

    left join 
        $wpdb->postmeta my_field_meta on (p.ID = my_field_meta.post_id and 
                                          my_field_meta.meta_key = 'subscribe') 
    

    Where “subscribe” it’s the name of your custom field. So your code could be:

     $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(p.post_date)
        FROM $wpdb->posts as p
        LEFT JOIN 
            $wpdb->postmeta my_field_meta on (p.ID = my_field_meta.post_id and 
                                              my_field_meta.meta_key = 'subscribe')     
        WHERE MONTH(p.post_date) = '$thismonth'
        AND YEAR(p.post_date) = '$thisyear'
        AND p.post_type = 'post' AND p.post_status = 'publish'
        AND p.post_date < '" . current_time('mysql') . ''', ARRAY_N);