php - WordPress multisite , shows all sites but only want to display last 2 -


i need display last 2 posts of network of sites. i'm retrieving latest posts sites want display 2 of them.

i have following code:

<?php   $items = return_latest_posts();   global $wpdb;   $table_search = $wpdb->prefix . "searchinfo";   $query = "select * `$table_search`";   $wpdb->show_errors();   $results = $wpdb->get_results($query);    foreach ($results $site){     $item = return_latest_posts_single_site($site->username,$site->password,$site->database,$site->host,$site->db_prefix);   ?>  <li>   <h4><?php echo $site->sitename; ?></h4>    <?php foreach($item $res){  ?>     <p class="date"><?php echo $res->post_date ?></p>     <h4><a href="<?php echo $res->guid; ?>" target='_blank'><?php echo $res->post_title ?></a></h4>   <?php } ?>    <hr />  </li>  <?php } ?> 

how able show last 2 posts of sites together?

thanks in advance!

you might consider counting number of times $results foreach runs , restricting output first 2 laps:

<?php   $items = return_latest_posts();   global $wpdb;   $table_search = $wpdb->prefix . "searchinfo";   $query = "select * `$table_search`";   $wpdb->show_errors();   $results = $wpdb->get_results($query);    $count = 0;   foreach ($results $site){      $count++;     $item = return_latest_posts_single_site($site->username,$site->password,$site->database,$site->host,$site->db_prefix);      if ( $count < 3) {    ?>      <li>       <h4><?php echo $site->sitename; ?></h4>        <?php foreach($item $res){  ?>         <p class="date"><?php echo $res->post_date ?></p>         <h4><a href="<?php echo $res->guid; ?>" target='_blank'><?php echo $res->post_title ?></a></h4>       <?php } ?>        <hr />      </li>  <?php }} ?>  

more information on $wpdb;


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -