Created
February 27, 2015 16:31
-
-
Save scheurta/605e1a318e8ffec2ccdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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