Author template Multiple Custom Post type queries
-
Hi all, I am an extreme WP novice… and am basically trying to figure out as I go.
I have created a Author page for a WP site, where I want to display each of the authors published CPT’s separately/categorically. I have managed to achieve this by doing separate WP_Query’s for each CPT and then resetting the query each time etc…
Here is my code:
<div class="tab-container" id="tab-container"> <ul class="etabs"> <li class="tab active"><a href="#maintab1" class="active">TAB1</a></li> <li class="tab"><a href="#maintab2" >TAB2</a></li> <li class="tab"><a href="#maintab3" >TAB3</a></li> </ul> <div class="panel-container"> <div id="maintab1"> <div id="tab-container-inner"> <?php echo '<ul style="margin-left: 75px;" class="etabs">'; $postTypes = array('post_type1', 'post_type2', 'post_type3', 'post_type4'); $loopTypes = new WP_Query( array( 'post_type' => $postTypes, 'author' => $curauth->ID )); foreach ($postTypes as $postType) { if ( $loopTypes->have_posts() ) { echo '<li class="tab"><a href="#'.$postType.'"><span class="tab">'.$postType.'</span></a></li>'; }else{ return; } } wp_reset_query(); echo '</ul>'; ?> <div> <?php $current_cpt = 'post_type1'; $loop = new WP_Query( array( 'post_type' => $current_cpt, 'author' => $curauth->ID, 'posts_per_page' =>-1, 'orderby' => 'title', 'order' => 'DESC')); if ( $loop->have_posts() ) : $obj = $wp_post_types[$current_cpt]; echo '<div id="'.$current_cpt.'">'; echo '<h2>'.$obj->labels->singular_name.'</h2>'; ?> <div id="portfolio-image-wrap"><span id="portfolio-image-wrap-shadow"></span> <img id="main-image" class="<?php echo $current_cpt;?>"> <?php echo '<div>'; echo '<ul id="items" class="' . $current_cpt . '">'; while ($loop->have_posts()) : $loop->the_post(); echo '<div></div>'; //Display some layout stuff $current_cpt endwhile; echo "</ul>"; wp_reset_query(); wp_reset_postdata(); $current_cpt = ''; echo '</div>'; endif; $current_cpt = 'post_type2'; $loop = new WP_Query( array( 'post_type' => $current_cpt, 'author' => $curauth->ID, 'posts_per_page' =>-1, 'orderby' => 'title', 'order' => 'DESC')); if ( $loop->have_posts() ) : $obj = $wp_post_types[$current_cpt]; echo '<div id="'.$current_cpt.'">'; echo '<h2>'.$obj->labels->singular_name.'</h2>'; ?> <div id="portfolio-image-wrap"><span id="portfolio-image-wrap-shadow"></span> <img id="main-image" class="<?php echo $current_cpt;?>"> <?php echo '<div>'; echo '<ul id="items" class="' . $current_cpt . '">'; while ($loop->have_posts()) : $loop->the_post(); echo '<div></div>'; //Display some layout stuff $current_cpt endwhile; echo "</ul>"; wp_reset_query(); wp_reset_postdata(); $current_cpt = ''; echo '</div>'; endif; $current_cpt = 'post_type3'; $loop = new WP_Query( array( 'post_type' => $current_cpt, 'author' => $curauth->ID, 'posts_per_page' =>-1, 'orderby' => 'title', 'order' => 'DESC')); if ( $loop->have_posts() ) : $obj = $wp_post_types[$current_cpt]; echo '<div id="'.$current_cpt.'">'; echo '<h2>'.$obj->labels->singular_name.'</h2>'; ?> <div id="portfolio-image-wrap"><span id="portfolio-image-wrap-shadow"></span> <img id="main-image" class="<?php echo $current_cpt;?>"> <?php echo '<div>'; echo '<ul id="items" class="' . $current_cpt . '">'; while ($loop->have_posts()) : $loop->the_post(); echo '<div></div>'; //Display some layout stuff $current_cpt endwhile; echo "</ul>"; wp_reset_query(); wp_reset_postdata(); $current_cpt = ''; echo '</div>'; endif; ?> </div> </div> </div> <div id="maintab2"> </div> <div id="maintab3"> </div>I need help with two things:
– I know this is not good practice to achieve this???
– How do i get authors post types, where he/she has posted in ONLY???
Viewing 14 replies - 1 through 14 (of 14 total)
Viewing 14 replies - 1 through 14 (of 14 total)
The topic ‘Author template Multiple Custom Post type queries’ is closed to new replies.