Skip to content

Instantly share code, notes, and snippets.

@ellegaarddk
Last active October 10, 2023 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ellegaarddk/b043baf9b28ee65fcbe98dc7d7bc8ea1 to your computer and use it in GitHub Desktop.
Save ellegaarddk/b043baf9b28ee65fcbe98dc7d7bc8ea1 to your computer and use it in GitHub Desktop.
Get the post-type 'People' posts from the same custom taxonomy - WordPress, custom post type (CPT)
<?php
$id = get_post($post->ID);
$tax = get_the_terms($id, 'position');
$args = array(
'post_type' => 'people',
'tax_query' => array(
array(
'taxonomy' => 'position',
'field' => 'slug',
'terms' => $tax[0]->slug,
),
),
);
$loop = new WP_Query( $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment