• Resolved Pea Lutz

    (@misfist)


    Hi,

    Thanks much for the excellent plugin!

    Currently, I’m using a modified version of your plugin that displays post data a bit differently. While this is working fine, I won’t be able to take advantage of plugin updates.

    So, I’m wondering if it’s possible to use the plugin to return an array of posts rather than output the posts. This would enable me to iterate through the posts and display them as I’d like.

    Please let me know if more explanation is needed.

    https://www.ads-software.com/plugins/network-latest-posts/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    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.

    Thread Starter Pea Lutz

    (@misfist)

    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.

    Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Return Array of Posts’ is closed to new replies.