Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Dear friends this is my arguments for WP_Query.

$args = array('post_type' => 'job_listing',
'relation' => 'OR',
    'meta_query' => array(
        'relation' => 'OR',
        array(
            'key' => 'app_trailer-type',
            'value' => $job_tailor,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'app_pay-type',
            'value' => $app_pay_type,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'geo_address',
            'value' => $geo_address,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'geo_country',
            'value' => $geo_country,
            'compare' => 'LIKE'
        ),
        array(
            'key' => 'geo_short_address',
            'value' => $geo_short_address,
            'compare' => 'LIKE'
        ),
    ),
);

WordPress Returns query like.

SELECT SQL_CALC_FOUND_ROWS wp_posts.id
FROM   wp_posts
       INNER JOIN wp_postmeta
               ON ( wp_posts.id = wp_postmeta.post_id )
       INNER JOIN wp_postmeta AS mt1
               ON ( wp_posts.id = mt1.post_id )
       INNER JOIN wp_postmeta AS mt2
               ON ( wp_posts.id = mt2.post_id )
       INNER JOIN wp_postmeta AS mt3
               ON ( wp_posts.id = mt3.post_id )
       INNER JOIN wp_postmeta AS mt4
               ON ( wp_posts.id = mt4.post_id )
WHERE  1 = 1
       AND wp_posts.post_type = 'job_listing'
       AND ( wp_posts.post_status = 'publish'
              OR wp_posts.post_status = 'expired'
              OR wp_posts.post_status = 'tr_pending'
              OR wp_posts.post_status = 'tr_failed'
              OR wp_posts.post_status = 'tr_completed'
              OR wp_posts.post_status = 'tr_activated'
              OR wp_posts.post_status = 'private' )
       AND ( ( wp_postmeta.meta_key = 'app_trailer-type'
               AND Cast(wp_postmeta.meta_value AS CHAR) LIKE '%Flatbed%' )
              OR ( mt1.meta_key = 'app_pay-type'
                   AND Cast(mt1.meta_value AS CHAR) LIKE '%Per Week%' )
              OR ( mt2.meta_key = 'geo_address'
                   AND Cast(mt2.meta_value AS CHAR) LIKE '%Davenport%' )
              OR ( mt3.meta_key = 'geo_country'
                   AND Cast(mt3.meta_value AS CHAR) LIKE '%United States%' )
              OR ( mt4.meta_key = 'geo_short_address'
                   AND Cast(mt4.meta_value AS CHAR) LIKE '%Davenport%' ) )
GROUP  BY wp_posts.id
ORDER  BY wp_posts.post_date DESC
LIMIT  0, 10  

please help, i can't understand why it creates inner join 5 times on one table.

share|improve this question
    
One JOIN for each meta_query. What exactly don’t you understand? –  toscho Oct 28 '13 at 11:12
    
normally query have a one time inner join on table then why wordpress create five times innser join on table. it take more load this is not way to inner join query. –  renishkhunt Oct 28 '13 at 11:15
    
You're using meta for taxonomy like data. meta_query queries, especially complex ones do not perform well at all. –  Chris_O Oct 28 '13 at 15:52
    
Unfortunately the best answer to "why" is "because it works like that". Complex meta queries does produce SQL queries ike this in WordPress and you might want to look into modifying raw SQL instead. –  Rarst Oct 28 '13 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.