Refers to FiboSearch Pro only

Searching for custom post types

Starting with version 1.30.0, FiboSearch now supports displaying custom post types (CPTs) in search results.

Table of Contents

Enabling search for custom post types

Enabling search for custom post types involves three essential steps:

  1. Register the CPT with FiboSearch.
  2. Select the custom post type in the FiboSearch settings.
  3. Rebuild the search index.

The following instructions will walk you through each step.

To include custom post types in your search results with FiboSearch, you need to register them using the code provided below. This example demonstrates how to register two custom post types: testimonial and designer. There are two methods for registration: the first allows you to register using the CPT’s slug, while the second method enables you to define custom labels that FiboSearch will display in the search results.

add_filter( 'dgwt/wcas/indexer/post_types', function ( $post_types ) {
   $post_types[] = 'testimonial';

   $post_types[] = [
      'post_type' => 'designer',
      'labels'    => [
         'name'          => 'Designers',
         'singular_name' => 'Designer',
      ]
   ];

   return $post_types;
} );

Learn how to add this snippet to your WordPress.

Replace testimonial and designer with the slugs of your custom post types.

By default, FiboSearch searches only in CPT titles. If you want to search within the description as well, use this code:

add_filter( 'dgwt/wcas/indexer/post_source_query/testimonial/description', '__return_true' );

Learn how to add this snippet to your WordPress.

Make sure to change testimonial to the correct CPT slug.

Once the code is added, navigate to WooCommerce > FiboSearch > Autocomplete and select the custom post types you want to search within under the “Non-products in autocomplete” section:

FiboSearch: select custom post types to show in autocomplete

Save the settings and allow the search index to rebuild. Once the index is rebuilt, you will be able to search for your custom post types:

FiboSearch: show custom post types in autocomplete

Displaying custom post types on the search results page

By default, the WooCommerce search results page only shows products. To display custom post types on the results page, use the [fibosearch_posts_results] shortcode with the appropriate parameters. Here’s an example of how to add the shortcode:

add_action( 'woocommerce_no_products_found', function () {
   if ( ! \DgoraWcas\Helpers::isProductSearchPage() ) {
      return;
   }
   echo do_shortcode( '[fibosearch_posts_results post_type="designer" layout=grid show_image]' );
   echo do_shortcode( '[fibosearch_posts_results post_type="testimonial" layout=grid show_image]' );
} );
add_action( 'woocommerce_before_shop_loop', function () {
   if ( ! \DgoraWcas\Helpers::isProductSearchPage() ) {
      return;
   }
   echo do_shortcode( '[fibosearch_posts_results post_type="designer" layout=grid show_image]' );
   echo do_shortcode( '[fibosearch_posts_results post_type="testimonial" layout=grid show_image]' );
} );

Learn how to add this snippet to your WordPress.

You can also use this shortcode with your page builder. For Elementor, there is a “FiboSearch Posts Search Results” widget, which allows you to select the post types to display:

Elementor custom post type FiboSearch widget