Skip to content

Instantly share code, notes, and snippets.

@garraflavatra
Last active July 9, 2021 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garraflavatra/6877a73443660cd39287a826aeb3d1cf to your computer and use it in GitHub Desktop.
Save garraflavatra/6877a73443660cd39287a826aeb3d1cf to your computer and use it in GitHub Desktop.
How to query WordPress posts with a custom taxonomy term.
<?php
$posts = get_posts(
array(
'numberposts' => 20,
'post_type' => 'custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'custom_taxonomy',
'field' => 'slug',
'terms' => array( 'termslug1', 'termslug2' )
)
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment