Hello,
This is not possible right now without editing the source code. If you are willing to do that below you will find a quick explanation.
This plugins contains multiple parameters that are used to filter posts, some of these parameters are used before pulling posts and others after posts have been retrieved from database.
Parameters such as “full_meta” and others related to front-end (what users see) are applied once posts are being displayed. It seems you don’t need those because you want to handle this by yourself.
To get an array of posts, you could delete everything from line 617 to 1950 (please check the source code here: network-latest-posts.php), return the $all_posts variable which contains all posts pulled from database.
Here is how it should look like after deleting those lines:
...
// Return array of posts
return $all_posts;
// Reset post data
wp_reset_postdata();
}
Link to the whole function in Gist, replace the original function network_latest_posts($parameters){} in network-latest-posts.php with this one: nlposts-arrayReturn.php.
Please bear in mind that all changes made to the source code will be deleted once the plugin gets updated. I recommend you to change the plugin’s name to “Network Latest Posts Custom” or something like that to avoid losing them.
I hope this helps,
Best regards.
Thank you very much for this! It seems to work, except that the array doesn’t hold the site ID, so I’d need to write something to get that…
Ideally, the plugin would enable you to specify whether to return an array containing all the data or display the posts.
Hello,
There is an array for that too, it is named: $all_blogkeys which matches posts IDs with blogs IDs. It is useful to know where each post came from.
Below you’ll find an example code used to loop through posts for each blog and get its format:
foreach( $all_posts as $post ) {
switch_to_blog( $all_blogkeys[$post->guid] );
$post_format = get_post_format( $post->ID );
restore_current_blog();
}
This will parse all posts array, get its blog ID (from the blog keys array), retrieve the post format and finally return to the current blog.
I hope this information helps.