WordPress.org

Ready to get started?Download WordPress

Forums

added custom-post-type to query - but need help with side effects (1 post)

  1. Niki Campbell
    Member
    Posted 1 year ago #

    Hi there - I have used the code below to add the CPT to the query. But in the dashboard all the pages, CPT's, and posts are listed under "posts". Is there a better way to do this?

    SITE:
    http://learn.rupertport.com/?port_plan=whats-in-my-bread

    CODE:

    add_filter( 'pre_get_posts', 'add_to_query' );
    
        function add_to_query( $query ) {
            // if ( home() ) {
                if( $query->query_vars['suppress_filters'] ) // TODO check if necessary
                    return $query;
                $supported = $query->get( 'post_type' );
                if ( !$supported || $supported == 'post' )
                    $supported = array('post', 'port_plan', 'page' );
                elseif ( is_array( $supported ) )
                    array_push( $supported, 'port_plan' );
                $query->set( 'post_type', $supported );
                return $query;
            //}
        }

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Topic Closed

This topic has been closed to new replies.

About this Topic