• markhof

    (@markhof)


    Hi,

    I’ve successfully added a custom post type (people) to the main search form for my site, by adding this function in my child theme:

    ———————–

    
    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    
    add_filter( 'pre_get_posts', 'tgm_io_cpt_search' );
    /**
     * This function modifies the main WordPress query to include an array of 
     * post types instead of the default 'post' post type.
     *
     * @param object $query  The original query.
     * @return object $query The amended query.
     */
    function tgm_io_cpt_search( $query ) {
    	
        if ( $query->is_search ) {
    	$query->set( 'post_type', array( 'people', 'post', 'pages' ) );
        }
        
        return $query;
    

    —————-

    Unfortunately it overwrote the other search form I’m using in the people section. I want that search form to pull in the people post type only. currently both search forms are now pulling in ( ‘people’, ‘post’, ‘pages’ ). I used Ivory search to create the people search.

    • This topic was modified 6 years ago by Jose Castaneda. Reason: added backticks for code
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘multiple search forms with custom custom post type type’ is closed to new replies.