Skip to content

Instantly share code, notes, and snippets.

@scheurta
Created February 27, 2015 16:31
Show Gist options
  • Save scheurta/605e1a318e8ffec2ccdb to your computer and use it in GitHub Desktop.
Save scheurta/605e1a318e8ffec2ccdb to your computer and use it in GitHub Desktop.
$category_arr = array();
$current_category = get_the_category();
foreach ( $current_category as $cat ) {
$category_arr[] = $cat->term_id;
}
$args = array(
'post_type' => 'cpt_name',
'post_status' => 'publish',
'post__not_in' => array( get_the_id() ),
'category__in' => $category_arr,
);
$post_query = new WP_Query( $args );
if ( $post_query->have_posts() ) {
while( $post_query->have_posts() ) {
$post_query->the_post();
//...
}
wp_reset_postdata();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment