WordPress.org

Forums

How to query all posts from all custom post type (3 posts)

  1. imoddesign
    Member
    Posted 2 years ago #

    Hello, help me please!, I need to query all posts from all custom post type to show on homepage.

  2. monikos
    Member
    Posted 2 years ago #

    You need categorization. Search for some plugin maybe.

  3. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with this in your theme's functions.php:

    add_action( 'pre_get_posts', 'post_type_home_query' );
    function post_type_home_query( $query ) {
    	/* not an admin page and is it's the main query */
    	if ( !is_admin() && $query->is_main_query() ) {
    		if ( is_home() ) {
    			$args=array(
    				'public'   => true,
    				'_builtin' => false
    			);
    			$post_types = get_post_types( $args, 'names', 'and' );
    			if ( !empty( $post_types ) )
    				$query->set( 'post_type', array_keys( $post_types ) );
    		}
    
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic