How to search only for specific content types with the Elementor search form?

Table of contents

Elementor Pro besitzt ein Widget namens “Suchformular”. Dieses eignet sich für die hübsche Gestaltung von Suchformularen. In der Programmatik ist dieses Suchformular leider beschränkt.

Question: How can I modify the Elementor search form to restrict the search to certain content types (e.g. search only for Posts, Pages, Products, FAQ, ...)?

Answer / Solution:

  1. Give the widget a unique ID, e.g. mnc_search_posts
  2. Insert the following code into functions.php:
    add_action( 'elementor_pro/search_form/after_input', function( \ElementorPro\Modules\ThemeElements\Widgets\Search_Form $form ) {
       if($form->get_settings()['_element_id'] ?? null === 'mnc_search_posts') {
          echo '';
       }
    }, 10, 1 );