A function to call 10 latest post with no repeated author
-
Hello there~ Thank you for clicking in first.
I am trying to create a list that contains the latest post from different authors & one specific category on the widget area. WordPress default to have the latest post widget, but if one of the authors writes a few posts the roll, he/she takes all the spots on the latest post widget. To be simply, I write down the requirement in points:-10 latest posts
-no repeated author
-specific categorySo ten posts should be all from different authors and sort by date.
This is my attempt, please point out what I am doing wrong =D Newbie in programming
$args = array( 'order' => 'DESC', 'orderby' => 'date', 'cat' => 39 ); $query = new WP_Query($args); $final= array_fill(0, 10, array('','')); if( $query->have_posts() ) { while ($query->have_posts()) { for($i=0; $i < 10; $i++ ){ $query->the_post(); $authors = get_the_author_meta('ID'); if ($final[$i][0] != $authors){ $final[$i][1] = ' <li><a href="'.get_permalink().'">'.get_the_title().'</a></li> '; } } } } print_r ($final);
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘A function to call 10 latest post with no repeated author’ is closed to new replies.