Last active
January 7, 2016 21:31
-
-
Save diegoliv/1521cd17f765b11e1ab0 to your computer and use it in GitHub Desktop.
Meta Query complexa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; | |
$roi_min = (get_query_var('roi_min')) ? intval( get_query_var('roi_min') ) : false; | |
$roi_max = (get_query_var('roi_max')) ? intval( get_query_var('roi_max') ) : false; | |
$args = array( | |
'post_type' => 'post', | |
'tax_query' => array(...), | |
'posts_per_page' => 10, | |
'paged' => $paged, | |
'meta_query' => array( | |
'relation' => 'OR', | |
array( | |
'relation' => 'AND', | |
array( | |
'key' => 'roi_min', | |
'value' => $roi_min, | |
'compare' => '>=', | |
'type' => 'NUMERIC' | |
), | |
array( | |
'key' => 'roi_max', | |
'value' => $roi_max, | |
'compare' => '<=', | |
'type' => 'NUMERIC' | |
) | |
), | |
array( | |
'relation' => 'AND', | |
array( | |
'key' => 'roi_min', | |
'value' => $roi_min, | |
'compare' => '>=', | |
'type' => 'NUMERIC' | |
), | |
array( | |
'key' => 'roi_max', | |
'value' => '', | |
) | |
), | |
array( | |
'relation' => 'AND', | |
array( | |
'key' => 'roi_min', | |
'value' => '', | |
), | |
array( | |
'key' => 'roi_max', | |
'value' => '', | |
), | |
), | |
array( | |
'relation' => 'AND', | |
array( | |
'key' => 'roi_min', | |
'compare' => 'NOT EXISTS', | |
), | |
array( | |
'key' => 'roi_max', | |
'compare' => 'NOT EXISTS', | |
) | |
), | |
), | |
); | |
$reports = new WP_Query( $args ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment