Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save khromov/ef70650f63cf9bc8f1e3 to your computer and use it in GitHub Desktop.
Save khromov/ef70650f63cf9bc8f1e3 to your computer and use it in GitHub Desktop.
wordpress-taxonomy-query-acf-taxonomy-field-example
$post_id = 1; //Post ID
$post_taxonomies = get_field('assigned-taxonomies', $post_id);
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'your-taxonomy',
'field' => 'term_id',
'terms' => $post_taxonomies
),
),
);
$query = new WP_Query( $args );
//Print result
print_r($query->posts);
//Print raw SQL
print_r($query->request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment