Last active
May 2, 2016 13:11
-
-
Save lewismcarey/9511152 to your computer and use it in GitHub Desktop.
WORDPRESS WP Query Taxonomy and Meta query shorthand/longhand methods
This file contains 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
// 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' | |
) | |
) | |
); |
This file contains 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about OR instead of AND?