Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Created September 12, 2018 12:57
Show Gist options
  • Save tallesairan/ce39a433fd76d9f8c10477ea66cb4252 to your computer and use it in GitHub Desktop.
Save tallesairan/ce39a433fd76d9f8c10477ea66cb4252 to your computer and use it in GitHub Desktop.
lastProducts
<?php
function lastProducts($limit){
$sitesData = get_sites(['number' => 200000000]);
$posts = [];
foreach ( $sitesData as $sites_datumk=>$sites_datum ) {
$st = [];
switch_to_blog( $sites_datum->blog_id );
$st = get_posts([
'post_type'=>'product',
'posts_per_page' => $limit,
'orderby'=>'ID',
'order'=>'DESC' ]);
foreach ( $st as $itemk=> $item ) {
$site = [];
$site['blog_id']=$sites_datum->blog_id;
$site['product_id']=$item->ID;
$site['product']=get_blog_post($sites_datum->blog_id,$item->ID);
$site['thumb']= get_the_post_thumbnail_url($item->ID,'default');
$posts[] = $site;
}
}
return $posts
}
lastProducts(2); /// 2 produtos por página
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment