Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    For a specific post type search query, you will need to create custom search form which has contained hidden field to make search for specific post type. Here default form isn’t working.

    Here is the custom search form.

    <form role=”search” method=”get” id=”searchform” action=”<?php echo home_url( ‘/’ ); ?>”>
    <input type=”hidden” name=”post_type” value=”tv” /> //just include value as post type & for blog use post
    <input type=”text” value=”” name=”s” id=”s” placeholder=”Search videos…”/>
    <input type=”submit” id=”searchsubmit” value=” ” />
    </form>

    Add post type name in form hidden field which i have made as bold it.

    Thank you.

    Theme Author Andrew Misplon

    (@misplon)

    Hi tokegameart

    Thanks for reaching out ??

    There isn’t front-end functionality for this built into WordPress or Ultra. You can implement this with a bit of custom development:

    1. Go to Plugins > Add New and install a plugin called Code Snippets.
    2. Go to Snippets > Add New and add a snippet, name it yourself and add the following in the snippet body:

    /**
     * Search the products post type only.
     */
    function ultra_products_search( $query ) {
    
        if ( $query->is_search && ! is_admin() ) {
            $query->set( 'post_type', array( 'products' ) );
        }
    
    	return $query;
    }
    
    add_filter( 'pre_get_posts', 'ultra_products_search' );

    3. NB. Select the option: Only run on site front end.
    4. Save changes and activate.

    For future queries on premium, please, contact us via email on [email protected], you can also make use of the forum at https://purothemes.com/support/forum/ultra-theme/.

    Theme Author Andrew Misplon

    (@misplon)

    Thanks for your help @girish.

    @tokegameart, please, try my suggestion first as it doesn’t require a child theme.

    Thread Starter tokegameart

    (@tokegameart)

    Hi @girish and @andrew, thanks for your help.
    I just figured it out, adding this line in “form” tag in my child theme

    <input name=”post_type” value=”product” type=”hidden” />

    i love Ultra theme, 5 Stars for this theme.

    Theme Author Andrew Misplon

    (@misplon)

    Awesome, glad you’ve made progress ?? Thanks for your support, it’s most appreciated. All the best.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Search Query’ is closed to new replies.