Skip to content

Instantly share code, notes, and snippets.

@michaelschofield
Created April 7, 2015 04:28
Show Gist options
  • Save michaelschofield/9f1e123eaff85aabf0f9 to your computer and use it in GitHub Desktop.
Save michaelschofield/9f1e123eaff85aabf0f9 to your computer and use it in GitHub Desktop.
<?php
$args_version_1 = array(
// The name of the custom field
'meta_key' => 'color',
// A specific value we might optionally look for
'meta_value' => 'blue',
// A comparison operator. E.g., != means "not equal to"
'meta_compare' => '!='
// We can specify a post type
'post_type' => 'crayon'
);
$args_version_2 = array(
/* For more complex custom field queries, our syntax changes
* to use the meta_query syntax. The meta_query is an array
* of arrays that can represent multiple custom fields and
* their relationship to one another. This example would display
* either colors that aren't blue or shapes that are squares.
*/
'meta_query' = array(
'relation' => 'OR',
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'NOT LIKE',
),
array(
'key' => 'shape',
'value' => 'square'
'compare' => '=='
)
)
);
$the_query = new WP_Query( $args_pick_a_version );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment