Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

wp query compare like and or

//WP QUERY EXAMPLE WITH MIXED AND & OR in a LIKE comparison
  
$retoArray = array(
  'key'		=> 'reto',
  'value'		=> $data->get_param('reto'), 
  'compare'	=> 'LIKE'
);

$zonaArray = array(
  'relation' => 'OR'
);

//$zonaData = filter_var ( $zonaData, FILTER_SANITIZE_STRING);
//$zonaData = explode(',',$data->get_param('zona-articular'));

foreach($zonaData as $zona){
  array_push($zonaArray,
             array(
               'key'		=> 'zona_articular',
               'value'		=> $zona, 
               'compare'	=> 'LIKE'
             )
            );
}

query_posts(
  array(  
    'post_type' => 'casos-estudio',
    'post_status' => 'publish',
    'posts_per_page' => -1, 
    'orderby' => 'title',  
    'meta_query'	=> array(
      'relation' => 'AND',
      $retoArray,
      $zonaArray
    ),        
  ));
 
PREVIOUS NEXT
Tagged: #wp #query #compare
ADD COMMENT
Topic
Name
7+9 =