Can i show more than 25 posts and include blogs

Hi, in recent global post widget maximum posts to show is 25, can i increase that number and can i set up include option instead of exclude blogs?

  • Tyler Postle
    • CGO

    Hey Nikola,

    Hope you’re doing well today!

    You can do “include” instead of exclude by using this function to your main sites child theme functions.php or through an mu-plugin:

    add_filter( 'network_posts_where', 'rgpwidget_include_blogs', 10, 2 );
    if ( !function_exists( 'rgpwidget_include_blogs' ) ) :

    function rgpwidget_include_blogs( $where, Network_Query $query ) {
    $include_blogs = "1, 3"; // Add here comma seperated blog ids from where you want to display posts
    return $where . sprintf( ' AND %s.BLOG_ID IN (%s) ', $query->network_posts, $include_blogs );
    }
    endif;

    As mention in the code comment, just swap the “1, 3” with the blogs you want posts included from.

    Thanks to my colleague @vinod Dalvi for that code from this post: https://premium.wpmudev.org/forums/topic/is-there-an-option-to-only-display-posts-from-specific#post-705486 :slight_smile:

    As for increasing the max blog posts you can edit the widget-recent-global-posts.php file and change the “25” to any number you like for the max amount posts :slight_smile:

    Open the file and search for “25”, it is the only “25” in the file. I’ve attached a screenshot just to illustrate.

    **Keep in mind that this is editing a core file so it will be overwritten on updates back to 25. You will want to make note of the change you do so you can easily add it again later on.

    If you need any further assistance just let us know!

    Cheers,

    Tyler

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.