• Hello everyone,
    I need to do a custom query that gives me the posts that have the value “$value” in the custom field “custom1” or “custom2”.
    Is there something similar?

    $querydetails = "
       SELECT wposts.*
       FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
       WHERE wposts.ID = wpostmeta.post_id
    
       WHERE (wpostmeta.meta_key = 'custom1'
    		AND wpostmeta.meta_value = '$value')
    
    	OR (wpostmeta.meta_key = 'custom2'
    		AND wpostmeta.meta_value = '$value')
    
       AND wposts.post_status = 'publish'
       AND wposts.post_type = 'post'
       ORDER BY wposts.post_date DESC
     ";

    the best is:
    if is in both “custom1” and “custom2” ignore one of this

    thanks for your attention

  • The topic ‘Multiple meta_key with OR condition?’ is closed to new replies.