I have created CPT ( Custom Post Type ) called Recipes.

I want to display all me recipe in Vertical Tabs.

For Example; check the image below i have created. Image Example Click Here

On the left hand side as in image i want to display Post title of CPT Recipes & on right hand side i want to display the content of that recipe.

How can i do that in Wordpress ? Anyone please help.

I have tried many tutorials, but all in vain.

This is code which i am trying now. close but not perfect.

     <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
     <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>

    <div id="tabs">
        <?php //WordPress loop for custom post type
             $my_query = new WP_Query('post_type=training_courses');
                 while ($my_query->have_posts()) : $my_query->the_post(); 

                <a href="#<?php the_ID(); ?> "><?php the_title(); ?></br>
                <?php endwhile; ?>

               <div class="side-tc">    
                   <div id="<?php the_ID(); ?> ">
                       <?php the_title(); ?></br>
                   <?php wp_reset_query();?>

<script type="text/javascript">
    .addClass('ui-tabs-vertical ui-helper-clearfix');

But On Right Side ( Content ), it show all the recipes content. Not the one selected.

Please help me fix this or if you can suggest me to any tutorial.


Appreciate your help.



You should run WP Query twice. Once for the li elements and the other for the div elements. You do not seem to be doing this? If you want to use jQuery tabs or accordion you may have to run the wp query twice or save the query results in an array and use a for/while loop. The later is better as it has less impact on the database.

  • No need to query twice. You can loop thru the result as many times as you like. Once to build an array of titles only (for the list elements and once for the contents on the side.
    – jdm2112
    Nov 5 '15 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.