Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

MUltiple loops inside author.php WordPress

  • SOLVED

[[LINK href="http://wpquestions.com/question/showChronoLoggedIn/id/12510"]]http://wpquestions.com/question/showChronoLoggedIn/id/12510[[/LINK]]

Using this example...
[[LINK href="https://codex.wordpress.org/Author_Templates#Sample_Template_File"]]https://codex.wordpress.org/Author_Templates#Sample_Template_File[[/LINK]]

Answers (1)

2016-01-17

Romel Apuya answers:

/*Display all the author's posts from the custom post type (AAAAAAA)*/
<?php
$authorid = the_author_meta('ID');
$args=array('author'=>$authorid,'post_type'=>'AAAAAAA', 'numberposts'=> -1);
$cquery=new WP_Query($args);
if($cquery->have_posts()):
while($cquery->have_posts()):
$cquery->the_post();
?>
<p><?php the_title();?></p>
<?
endwhile;
wp_reset_postdata();
endif;

?>

/*postt type BBBBBBB*/
<?php
$args2=array('author'=>$authorid,'post_type'=>'BBBBBBB', 'numberposts'=> -1);
$cquery2=new WP_Query($args2);
if($cquery2->have_posts()):
while($cquery2->have_posts()):
$cquery2->the_post();
?>
<p><?php the_title();?></p>
<?
endwhile;
wp_reset_postdata();
endif;
?>
/*Display the author's user meta from their profile*/
<div class="author-description">
<h3 class="author-title"><?php echo get_the_author(); ?></h3>
<p class="author-bio">
<?php the_author_meta( 'description' ); ?>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
<?php printf( __( 'View all posts by %s', 'twentyfifteen' ), get_the_author() ); ?>
</a>
</p>
</div>

/*List all the author's normal posts from the author*/
<?php
$args3=array('author'=>$authorid,'post_type'=>'post', 'numberposts'=> -1);
$cquery3=new WP_Query($args3);
if($cquery3->have_posts()):
while($cquery3->have_posts()):
$cquery3->the_post();
?>
<p><?php the_title();?></p>
<?
endwhile;
wp_reset_postdata();
endif;
?>

/*List all the author's posts from the custom post type (CCCCCCC)*/
<?php
$args4=array('author'=>$authorid,'post_type'=>'CCCCCCC', 'numberposts'=> -1);
$cquery4=new WP_Query($args4);
if($cquery4->have_posts()):
while($cquery4->have_posts()):
$cquery4->the_post();
?>
<p><?php the_title();?></p>
<?
endwhile;
wp_reset_postdata();
endif;
?>


pjeaje comments:

thanks, let me quickly test it


pjeaje comments:

<blockquote>Parse error: syntax error, unexpected '$args' (T_VARIABLE) .../author.php on line 23</blockquote>

line 23: $args=array('author'=>$authorid,'post_type'=>'aaa', 'numberposts'=> -1);


Romel Apuya comments:

sorry this

i already updated the code

lacking ; in the line... $authorid = the_author_meta('ID');


pjeaje comments:

I removed this line just above it and it seems to have fixed it?... $authorid = the_author_meta('ID')


pjeaje comments:

/*List all the author's normal posts from the author*/

It lists all the posts, I need it to list only the author's posts


Romel Apuya comments:

dont remove this line

$authorid = the_author_meta('ID')
add a semicolon

$authorid = the_author_meta('ID');


pjeaje comments:

OK, I think i've fixed it. I replaced $authorid = the_author_meta('ID') with $authorid = get_the_author_meta( ID, $userID ); and added $authorid = get_the_author_meta( ID, $userID ); before every loop... seems to work?


Romel Apuya comments:

ok. good it works..


pjeaje comments:

Do my changes make sense? I really don't know if it is the correct way to fix it?


Romel Apuya comments:

actually it will work with

$authorid = get_the_author_meta( 'ID' );


pjeaje comments:

ok thanks