How to Make a Search Bar?

I don’t know. My understanding is that none of the user-submitted designs in Cwicly have ever worked, or at least they’ve never worked for me. I think it’s an idea they promoted in the early days, during which I submitted my search bar, but then they disabled access to the submissions. This would at least explain why I’ve never been able to find other people’s submissions and use them on my site. Or maybe I did it wrong to begin with.

Perhaps one of the staff members can answer this, or you can contact them directly.

Hi, I got this search bar working. Great.
Is it possible to search only in posts or CPT’s??
Now i find also my header and my footer. I don’t want that.
I want a restriction on where to search.

Is that possible?

Hi @Lijn-B,

A search plugin is a possibility:

If you use this approach, it should work very well in combination with it:

@StrangeTech
Thank You for your answer.
I created the search as descripted above, and I’m happy with it. Allways trying to use as less plugins as possible.

Is there a way without plugin to restricht the search to (for example) pages and posts or CPT’s?

I now use a snippet for it, but I had hoped it could with Cwicly or Wordpress settings.

Here is the snippet:

function restrict_search_to_multiple_post_types($query) {
    if (!is_admin() && $query->is_search()) {
        $query->set('post_type', array('page', 'your_custom_post_type')); // Add multiple post types as an array
    }
    return $query;
}
add_filter('pre_get_posts', 'restrict_search_to_multiple_post_types');

Using this approach anything that works with the normal WordPress search should also work: