Skip to content

WordPress Search Redirect to Custom Post Type Archive

By geekerhub 7 min read

WordPress search form directing search results to a custom post type archive

WordPress search forms normally send visitors to the default search results page. For example, when someone searches for “phone”, WordPress may open a URL like this:

/? s= phone

But what if you want search results to appear on a specific Custom Post Type (CPT) archive instead?

For example, you may have a Courses post type and want its search form to send visitors to:

/ courses/? s= wordpress

You can do this by changing the search form’s action URL. In this tutorial, you’ll learn how to send WordPress search requests to a custom post type archive without installing a plugin.

Why WordPress Search Opens the Default Results Page

WordPress uses the s query parameter to identify a search request. A URL such as /?s=phone tells WordPress to search for the word “phone”.

However, the search form’s action attribute determines where the browser sends that request.

If your form uses:

<form action="/" method="get">

The search request goes to your website’s homepage URL. WordPress then handles it using the default search query.

To send the request to a Custom Post Type archive, you need to use that archive’s URL as the form action.

Simple Fix: Change the Search Form Action

Instead of sending the form to the homepage, point it to your custom post type archive.

For example, change this:

<form action="/" method="get">

To this:

<form action="/courses/" method="get">

Here is the complete search form:

<form action="/courses/" method="get">
    <input
        type="search"
        name="s"
        placeholder="Search courses"
    >

    <button type="submit">Search</button>
</form>

Replace /courses/ with the archive URL of your own Custom Post Type.

When a visitor searches for “WordPress”, the form sends the request to:

/ courses/? s= WordPress

Important: Make Sure WordPress Searches the Correct Post Type

Changing the form action sends the request to the archive URL, but it does not automatically guarantee that WordPress will restrict the search results to that post type.

For a reliable result, your Custom Post Type must have an archive enabled, and the search query must include the correct post type.

For example, if your registered post type key is courses, you can use this additional PHP snippet:

/**
 * Restrict search results on the Courses archive
 * to the courses custom post type.
 */
add_action( 'pre_get_posts', 'gh_search_courses_archive' );

function gh_search_courses_archive( $query ) {

    if ( is_admin() || ! $query->is_main_query() ) {
        return;
    }

    if ( $query->is_search() && is_post_type_archive( 'courses' ) ) {
        $query->set( 'post_type', array( 'courses' ) );
    }
}

Replace courses with the registered post type key used on your website. This code targets the main search query on the Courses archive and limits its results to that post type.

Note: If your post type archive does not already display search results as expected, test this query modification with your theme and other search plugins. Custom search implementations may use their own query logic.

How to Enable the Custom Post Type Archive

Your Custom Post Type must support an archive before you can use its archive URL as the search form action.

If you register the post type using PHP, make sure the has_archive option is enabled:

register_post_type( 'courses', array(
    'label'        => 'Courses',
    'public'       => true,
    'has_archive'  => true,
    'rewrite'      => array(
        'slug' => 'courses',
    ),
    'supports'     => array(
        'title',
        'editor',
        'thumbnail',
    ),
) );

In this example:

  • courses is the post type key.
  • has_archive => true enables the archive page.
  • slug => courses sets the archive URL to /courses/.

If you have recently changed the post type rewrite settings, visit Settings > Permalinks in your WordPress dashboard and click Save Changes. You do not need to change the permalink structure; saving the settings refreshes the rewrite rules.

Using Different Search Forms for Multiple Post Types

You can create separate search forms for different Custom Post Types. Each form can point to its own archive URL.

For example, a website with Courses, Events, and Products can use these forms:

Search Courses

<form action="/courses/" method="get">
    <input type="search" name="s" placeholder="Search courses">
    <button type="submit">Search</button>
</form>

Search Events

<form action="/events/" method="get">
    <input type="search" name="s" placeholder="Search events">
    <button type="submit">Search</button>
</form>

Search Products

<form action="/products/" method="get">
    <input type="search" name="s" placeholder="Search products">
    <button type="submit">Search</button>
</form>

Make sure each archive exists and that the corresponding search query is configured to return the intended post type. The Products example above is for a custom post type named products; WooCommerce’s built-in product post type and archive may require a different setup.

How to Use This with Elementor

If you are building your website with Elementor, you may not have direct control over the search form’s action URL through the standard widget settings.

You can use an HTML widget and add your own form:

<form action="/courses/" method="get">
    <input type="search" name="s" placeholder="Search courses">
    <button type="submit">Search</button>
</form>

If you prefer using Elementor’s search widget, check whether your version or any installed search extension provides a way to customize the form action or search query. The available options depend on the widget and its configuration.

Common WordPress Search Redirect Problems

  • Wrong action URL: Make sure the form action points to the correct archive URL.
  • Missing search field name: The input must use name="s" for a standard WordPress search request.
  • Archive not enabled: Check that the Custom Post Type is registered with has_archive enabled.
  • Wrong post type key: Use the registered post type key in your PHP query, not just its display label.
  • Rewrite rules not refreshed: Save your permalink settings after changing the post type rewrite configuration.
  • Search results include other post types: Check the main query and restrict its post_type where needed.

Frequently Asked Questions

Why does WordPress search go to the default search page?

Most standard search forms use the homepage as their action URL. The browser sends the search request there, so WordPress displays its normal search results page.

What should the search input name be?

For a standard WordPress search request, use name="s". WordPress reads this query parameter to identify the search term.

Can I create separate search forms for multiple Custom Post Types?

Yes. Give each form the archive URL of the relevant post type. You may also need to configure the main search query to return only that post type.

Do I need a plugin for this customization?

No. You can create the form using HTML and use a small PHP snippet to adjust the search query when required.

Will this work with every Custom Post Type?

It works with Custom Post Types that have a valid archive URL and support the required search query. Your theme or search plugin may need extra configuration if it uses a custom search system.

Conclusion

Sending WordPress search requests to a Custom Post Type archive is straightforward. Change the search form’s action URL to the archive URL and keep the search input name as s.

If you also want to limit the results to that post type, adjust the main search query using pre_get_posts. This gives visitors a more focused search experience without requiring an additional plugin.