Tuesday, September 13, 2022
HomeWordPress DevelopmentHow do I create a search kind that searches solely inside a...

How do I create a search kind that searches solely inside a customized put up kind?


My web site has a customized put up kind.
I would like to permit customers the power to go looking inside the customized put up kind. So I would just like the search outcomes to solely embrace posts of that individual put up kind.

I would prefer to additionally provide regular search.
That’s, I would like the positioning to have types which have the usual wordpress search, permitting customers the power to go looking inside the native put up sorts (Submit and Web page).

As a result of I wish to provide a traditional search alongside a customized search, I am unable to filter the search question with the ‘pre_get_posts’ hook. So the most suitable choice is to customized the search kind.

for the put up kind ‘mypost’ with the slug ‘myposts’, I’ve this way:

<kind position="search" methodology="get" 
      id="searchform block"
          class="search-form"
          motion="<?php echo esc_url(home_url("https://wordpress.stackexchange.com/")); ?>"
          >
    <div class="relative">
        <label class="screen-reader-text" for="s"><?php esc_html_e('Seek for:', 'text-domain'); ?></label>
        <enter          id="search-field"
          kind="search"
          class="search-field outline-none"
          worth="<?php echo esc_html(get_search_query()); ?>" identify="s" />
        <enter kind="hidden" identify="post_type" worth="myposts" />

        <button class="search-button cursor-pointer absolute right-0 top-0 bottom-0 m-auto py-5 px-4 ml-4" kind="submit" id="searchsubmit">
            <span class="sr-only"><?php esc_html_e('Search', 'text-domain'); ?></span>

        </button>

    </div> </kind>

Within the enter parameter ‘worth’, I’ve tried each ‘mypost’ and ‘myposts’.

For both worth, a search will return zero outcomes.

Situations of the customized put up kind do exist.

So: how can I create a working kind that may search just for leads to the goal customized put up kind?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments