• This is my code:

    $args = array(
    'post_type' => 'temas',
     'posts_per_page' => '15',
     'meta_key' => 'personas',
     'order' => 'asc',
     'orderby' => 'meta_value',
     'meta_query' => array(
    	'relation' => 'OR',
           array(
               'key' => 'idioma',
               'value' => $idio,
    		   'compare' => '=='
           ),
    	   array(
               'key' => 'idioma_2',
               'value' => $idio,
    		   'compare' => '=='
           )
       ),
    'post_status' => 'publish',
    );

    I want to get all post filtered by meta_keys idioma and idioma_2, and ordered by another meta_key called “personas”, but it does not work, if I remove the relation on meta_query all works, but i need the relation OR… I dont know what to do…

Viewing 1 replies (of 1 total)
  • Thread Starter CristianOspina

    (@cristianospina)

    This is a part of the SQL:
    AND (wp_postmeta.meta_key = 'personas' OR (mt1.meta_key = 'idioma' AND CAST(mt1.meta_value AS CHAR) = '') OR (mt2.meta_key = 'idioma_2' AND CAST(mt2.meta_value AS CHAR) = '') )
    apparently what happens is that the order meta_key is added to meta_query then the order does not affected, being ordained by default:
    GROUP BY wp_posts.ID ORDER BY wp_posts.post_date desc LIMIT 0, 15

    Then, there is another way to sort by meta_key without combining with meta_query?

    This is the same problem on StackOverflow. But I can not get my code works… Help please!

Viewing 1 replies (of 1 total)
  • The topic ‘Filter by two meta_keys and orderby another meta_key’ is closed to new replies.