I am trying to exclude posts with a specific meta_value with a specific meta_key while also sorting the posts by a meta_value with a different meta_key.
This is my current code for the WP_Query class:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => '50',
'meta_key' => 'release_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'paged' => $paged
);
$the_query = new WP_Query($args);
the sorting by a specific meta_value part is working fine but I am not sure what to add to get it to exclude posts with a specific meta_value with a different meta_key than the one used for sorting.
Any advice / help is very much appreciated.
I got this working with the code below:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => '50',
'meta_key' => 'release_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'undetermined_date',
'value' => 'TBA',
'compare' => '!=',
'type' => 'CHAR'
)
),
'paged' => $paged
);
$the_query = new WP_Query( $args );
I have changed the custom field type to check-boxes which returns true or false instead of a text box. How would I change this code for use with a check-boxes? Here is the code I have tried:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => '50',
'meta_key' => 'release_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'undetermined_date_toggle',
'value' => 'true',
'compare' => '==',
'type' => 'CHAR'
)
),
'paged' => $paged
);
$the_query = new WP_Query( $args );
pre_get_posts
rather than create a new query.