I need to get Related Posts for custom post type. This works only for post. But shows nothing for custom post type as wp_get_post_categories($id) returns nothing.
$related = get_posts( array( 'category__in' => wp_get_post_categories($id), 'numberposts' => $post_num, 'post__not_in' => array($id) ) );
I changed the above code. But still get nothing.
$category = get_the_terms( $id, 'cases' );
$cat = array();
if($category){
$cat[] = $category->term_id;
}
$related = get_posts( array( 'category__in' => $cat, 'numberposts' => $post_num, 'post__not_in' => array($id) ) );
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire