Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 134520

williamchan04 on "A function to call 10 latest post with no repeated author"

$
0
0

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 category

So 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 all articles
Browse latest Browse all 134520

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>