Skip to content

Instantly share code, notes, and snippets.

@platoosom
Created April 30, 2020 07:16
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 platoosom/8043b4c70f2434911f647ad3ea7a68ca to your computer and use it in GitHub Desktop.
Save platoosom/8043b4c70f2434911f647ad3ea7a68ca to your computer and use it in GitHub Desktop.
Wordpress query not include current post
$termlists = array();
$terms = get_the_terms( get_the_ID(), 'podcast-tag' );
if ( $terms && is_array( $terms ) ) {
foreach ( $terms as $term ) {
$termlists[] = $term->slug;
}
}
$query_args = array(
'post_type' => 'podcast',
'post_status' => 'publish',
'posts_per_page' => 3,
'tax_query' => array(
array(
'taxonomy' => 'podcast-tag',
'field' => 'slug',
'terms' => $termlists,
),
),
'post__not_in' => array(get_the_ID())
);
$query = new WP_Query( $query_args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment