I have two custom post types named products and recipes.In my product’s post type i add some products and now i want to add recipes regarding to those products.(like product P1 can have two recipes R1 and R2.I want to show those recipes button on product post type detail page.So that i can view recipes of those products.

Here is the code i created product post type and to view on frontend.

Creating Product Post Type-

add_action( 'init', 'create_post_type' )
function create_post_type() {
register_post_type( 'mazaproducts',
        'labels' => array(
            'name' => __( 'Mazaproducts' ),
            'singular_name' => __( 'Mazaproduct' )
    'public' => true,
    'has_archive' => true,

Displaying All Product Post Type-

 $loop = new WP_Query( array( 'post_type' => 'products', 'posts_per_page' => 10 ) ); ?>
<?php //echo $GLOBALS['wp_query']->request ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>
<div class="entry-content">
    <?php //the_content();
            $content = get_the_content();
            $content = strip_tags($content);
            echo substr($content, 0, 100);
    <div class="col-md-4 col-sm-4 col-xs-12">
        <div class="product_details_thumb mar_bot">
            if ( has_post_thumbnail() ) {


Read more here: How to make relationship in two custom post types using first post type’s id and slug in second post type’s reference


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: