Frontend Search

When you use the Content Egg, you can add each deals to the post. WordPress searches by titles of posts but what if you want to have such search form which can show results from affiliate networks directly (without creating posts for each deals). This is possible with Content Egg and Frontend Search function.

First of all, you need to create two things – a page with search form (or widget) and a page for results.

Creating search form

There are several ways to show the affiliate search form.

The first option is using a widget CE:Product search (find it in Appearance – Widget). It has the same styling as a standard wordpress widget. Just place a widget in a sidebar.

The second way is to use the Content Egg shortcode.

[content-egg-search-form]

The shortcode will generate a standard wordpress search form and will send users to the special page with results from affiliate modules instead of the wordpress search page.

This shortcode has also the same design as the standard wordpress search form.

Please, note, some themes can have extended the Content Egg search form. For example, Rehub has an additional shortcodes.

Search settings

Next step which you need to do is setup the page for output results. For this, go to Content EggSettingsGeneral and add the output shortcode to the text area Search page template.

I recommend to use there common shortcodes of the Content Egg.

For example

[content-egg-block template=offers_list]

Customization

To configure the search form create the ce-product-searchform.php file in the directory root of your theme (or a child theme). Add and customize the form code:

<form role="search" method="get" class="search-form" action="<?php echo esc_attr(\ContentEgg\application\ProductSearchWidget::getSearchFormUri()); ?>">
      <input type="text" name="s" placeholder="Product search...">
      <button type="submit">Search</button>
</form>

To configure the global page template with a search result you need to create the ce-product-search.php file in the directory root of your theme (or a child theme). Use code like the code in your template of page.php.

To configure product-search in the URL search form use a filter that should return a new slug:

add_filter('cegg_product_search_slug', 'example_callback');

Last updated