SELECT DISTINCT wposts.*
FROM wp_2_posts wposts, wp_2_postmeta wpostmeta, wp_2_postmeta wpostmeta1, wp_2_term_taxonomy, wp_2_terms, wp_2_term_relationships
WHERE wposts.ID = wpostmeta.post_id
AND wp_2_terms.term_id = '8'
AND wp_2_term_taxonomy.term_id = wp_2_terms.term_id
AND wp_2_term_taxonomy.term_taxonomy_id = wp_2_term_relationships.term_taxonomy_id
AND wp_2_term_relationships.object_id = wposts.ID
AND wpostmeta.meta_key = 'validity'
AND wpostmeta.meta_value > '".$logic_date."'
AND wpostmeta1.meta_key != 'permanent'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
ORDER BY wposts.post_date DESC