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

i'm normally doing more Design/CSS stuff, so please be patient if this question is a nobrainer...

My question is as follows: I have a custom post type, that has multiple custom fields. Now i need a custom loop that goes through several of these meta_keys, allowing duplicate posts.

My current SQL Statement works, but only uses one meta_key, as i can't figure out how to define the SQL statement that uses more meta_keys

  global $wpdb;
  $activelang = ICL_LANGUAGE_CODE;

  $myquery = "
     SELECT wposts.*
     FROM wp_posts wposts, wp_postmeta wpostmeta, wp_icl_translations wicl_translations
     WHERE wposts.ID = wpostmeta.post_id
     AND wpostmeta.meta_key = '_ws_prem_date'
     AND wposts.post_status = 'publish'
     AND wicl_translations.element_id = wposts.ID
     AND wicl_translations.language_code = '$activelang'
     AND wposts.post_type = 'event'
     ORDER BY CAST(wpostmeta.meta_value AS DATE) ASC
   ";

What I need would be:

Select all events as the above code does, AND if the post has also data entered in meta_keys date1 and date2 then put those posts multiple times in the object or array i use to create the custom loop.

share|improve this question
 
You want an OR, I think. Pure SQL questions are usually considered to be off topic per the faq though. –  s_ha_dum Sep 6 '13 at 13:35
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

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.