Mysql UNION on wordpress

I need help to develop a wordpress customization. I have the following mysql query with UNION instruction:

SELECT 
    wp_posts.* 
FROM wp_posts 
    INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
    LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) 
    LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' ) 
WHERE 
    ( wp_term_relationships.term_taxonomy_id IN (2151) ) AND 
    wp_posts.post_type = 'ait-dir-item' AND 
    ((wp_posts.post_status = 'publish')) AND 
    ( 
        ( 
        wp_postmeta.meta_key = 'dir_featured' AND 
        CAST(wp_postmeta.meta_value AS CHAR) = 'yes' 
        )
    ) 
GROUP BY wp_posts.ID 
UNION
SELECT 
    wp_posts.* 
FROM wp_posts 
    INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) 
    LEFT JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) 
    LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'dir_featured' ) 
WHERE 
    wp_term_relationships.term_taxonomy_id IN (2151) AND 
    wp_posts.post_type = 'ait-dir-item' AND 
    wp_posts.post_status = 'publish' AND 
    mt1.post_id IS NULL 
GROUP BY wp_posts.ID 

I want to translate this query with wordpress parameters. Is it possible?

Related posts

Leave a Reply

1 comment

  1. What is the purpose of this query ?
    Here is your query in WordPress mode

    $args = array(
        'cat'            => 2151,
        'post_type'      => 'ait-dir-item',
        'post_status'    => 'publish',
        'meta_query'     => array(
                    array(
                        'key'     => 'dir_featured',
                        'value'   => 'yes',
                        'compare' => '==',
                    ),
                ),
    
    );
    query_posts( $args );