Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lewismcarey/9511152 to your computer and use it in GitHub Desktop.
Save lewismcarey/9511152 to your computer and use it in GitHub Desktop.
WORDPRESS WP Query Taxonomy and Meta query shorthand/longhand methods
// shorthand method
$args = array(
'meta_key' => 'custom-field-key',
'meta_value' => 'custom-field-value',
'taxonomy-name' => 'term-value'
);
// longhand method
$args = array(
'meta_query' => array(
array(
'key' => 'custom-field-key',
'value' => 'custom-field-value'
)
),
'tax_query' => array(
array(
'taxonomy' => 'taxonomy-name',
'field' => 'slug',
'terms' => 'term-value'
)
)
);
# WORDPRESS WP Query Taxonomy and Meta query
This shows the two alternate methods to running taxonomy and post meta paramaters within WP Query.
* Shorthand version only accepts one postmeta key
* Longhand version is the full method and has much more flexiblity for complex queries
@geminorum
Copy link

How about OR instead of AND?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment