Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeweltheme/0b60a01c09c0fbc9318fb776b7c1a2ed to your computer and use it in GitHub Desktop.
Save jeweltheme/0b60a01c09c0fbc9318fb776b7c1a2ed to your computer and use it in GitHub Desktop.
WordPress - Query Custom Post Type and taxonomy term by ID
<?php
// gets the ID from a custom field to show posts on a specific page
$buildType = get_post_meta($post->ID, 'build_type_id', true);
// run query
query_posts(array(
'post_type' => 'portfolio',
'showposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'build-type',
'terms' => $buildType,
'field' => 'term_id',
)
),
'orderby' => 'title',
'order' => 'ASC' )
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment