add related posts to single page
-
HI,
i’m trying to show a module with the related products in a single post page.I created a cpt called “Product”, and a taxonomy called “category”.
What i want to do is to show, in the single post page, the other products of the same category.
Until now i successfully add the other posts with the function wp_get_recent_post, but of course i get all posts.
how i can pass the class to query ?
this is my code :
$args = array( 'numberposts' => '4', 'orderby' => 'rand', 'post_type' => 'product', 'post_status' => 'publish' ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ echo '<div class="col-md-3"><a href="' . get_permalink($recent["ID"]) . '">'. get_the_post_thumbnail($recent["ID"], 'thumbnail' ) . $recent["post_title"].'</a> </div> '; }
thank you
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘add related posts to single page’ is closed to new replies.