WordPress.org

Ready to get started?Download WordPress

Forums

How to get all posts (custom types) from all sites (2 posts)

  1. JacoboPolavieja
    Member
    Posted 3 years ago #

    Hello all,

    I'm building a project where I have several custom post types and taxonomies in the main blog and on the "child" sites/blogs.

    I need to show the last 50 "posts" whatever type they are in whatever site they've been published.

    I've look for plugins, although I'd prefer to code the thing myself. I got to MU-Helpers, which has the function:

    function get_all_blog_posts( $num_per_blog = 1, $orderby = 'date', $sort = 'post_date_gmt' )
    {
    	$posts = array();
    	$blogs = get_blog_list( 0,'all' );
    	foreach ( $blogs as $blog ):
    		switch_to_blog($blog['blog_id']);
    			$posts = array_merge( $posts, get_posts('orderby='.$orderby.'&numberposts='.$num_per_blog) );
    		restore_current_blog();
    	endforeach;
    
    	return _quicksort( $posts, $sort );
    }

    But I guess the "get_posts" function just retrieves the "post" post types, not the custom ones.

    Any idea how to achieve this?

    Thanks!

  2. JacoboPolavieja
    Member
    Posted 3 years ago #

    Sorry... re-reading (I don't know how I missed it the first time) the Codex for get_posts I see it accepts $post_type argument which can do, in principle, what I'm looking for.

    I'll try it out and answer back.

Topic Closed

This topic has been closed to new replies.

About this Topic