Skip to content

Instantly share code, notes, and snippets.

@ivo-ivanov
Created June 3, 2021 13:08
Show Gist options
  • Save ivo-ivanov/be9b7e0cc6f7f2dc9f785f6545480fbc to your computer and use it in GitHub Desktop.
Save ivo-ivanov/be9b7e0cc6f7f2dc9f785f6545480fbc to your computer and use it in GitHub Desktop.
Custom Meta Query in WP #wp #query
$args = array(
'post_type' => 'objekt',
'posts_per_page' => -1,
'no_found_rows' => true,
'suppress_filters' => false,
//Se the meta query
'meta_query' => array(
//comparison between the inner meta fields conditionals
'relation' => 'AND',
//meta field condition one
array(
'key' => 'stock',
'value' => 'Attika',
'compare' => '!=',
),
//meta field condition one
array(
'key' => 'lage',
'value' => 'Nassegasse 17',
//I think you really want != instead of NOT LIKE, fix me if I'm wrong
//'compare' => 'NOT LIKE',
'compare' => '=',
)
),
);
$the_query = new WP_Query($args);
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
endwhile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment