Set up product search for affiliate products

Add a product search to your site: search forms, result lists from your product database, live search in the shop APIs and the WordPress search redirect.

With a product search, visitors find the right product on your site themselves. affiliate-toolkit offers two kinds of search:

  • Search in your product database: the search form filters the products you have imported, by keyword, manufacturer, price, shop, categories or your own custom fields.
  • Live search in the shop interfaces: the keyword is sent directly to the APIs of your shops, and the results are shown without importing anything.

Both consist of two parts: a search form and a results shortcode on the target page. You can put both on the same page or send the form to a separate results page.

Prerequisites: the Frontend Search & Filter extension, installed and activated. It is included in the affiliate-toolkit passes. Without it, the shortcodes, templates and settings described here are not available.

Overview: the setup in four steps

  1. Create a results page and add a results shortcode: [atkp_list] for your product database or [atkp_livelist] for the live search.
  2. Add a search form with [atkp_searchform] and point it to the results page.
  3. Optional: redirect the WordPress search to the results page.
  4. Optional: show the search form in a sidebar with the filter widget.

The search only works with a results shortcode on the target page. The search form only passes the values in the URL; without the results shortcode no products are shown.

Insert a search form

The search form is inserted with the [atkp_searchform] shortcode. The easiest way is the shortcode generator: choose the output type Search Form, select a template and the target page, and copy the shortcode.

[atkp_searchform template='searchtext' targetpage='123'][/atkp_searchform]

The extension ships with these search form templates:

TemplateFieldsSuitable for
searchtextkeyword field and search buttonproduct database and live search
searchform (default)manufacturer, price slider, search button in one rowproduct database
searchboxmanufacturer, price slider, sort order and search button, stackedproduct database, narrow columns and sidebars
compareproductfour product selections and a compare button in one rowcomparing selected products
compareboxfour product selections and a compare button, stackedcomparing products in sidebars
The searchform template with a manufacturer selection, a price range slider from 0 € to 940 € and a search button
The search form template "searchform"

Attributes of [atkp_searchform]

AttributeDefaultDescription
templatesearchformName of a search form template from the table above or the ID of your own search form template.
targetpagecurrent pageID of the page with the results shortcode. If you leave it out, the form submits to the page it is on (or to the target page stored in your own template).
filteremptyPreset filter values in URL format, for example shop=12.

Where do I find the page ID? Open the results page in the WordPress editor. The ID is the number after post= in the address bar, for example post.php?post=123&action=edit. In the shortcode generator you simply pick the page from a list.

Show results from your product database

On the results page, an [atkp_list] shortcode without list ID shows the products that match the search. In the shortcode generator, choose the output type Dynamic Filter List, set fixed filters if you need them, enable Parse parameters and choose the number of items per page.

[atkp_list filter='productstatus=publish' template='grid_3_columns' parseparams='yes' itemsperpage='25'][/atkp_list]
Results page for the search "Nordklang" with product boxes of the Nordklang ANC 700 including features, pros and cons, price and buy button
Search results from the product database
AttributeDefaultDescription
parseparamsnoWith yes the shortcode reads the values of the search form from the URL. Required for every search.
filteremptyFixed filter in URL format. It is combined with the values from the search form, so you can, for example, limit a full-text search to one category.
itemsperpage0 (generator: 25)Number of products per page. If there are more results, a pagination is added.
templatewideTemplate for the results, e.g. grid_3_columns or the ID of your own template.
limitlist defaultMaximum number of products in total.

A missing parseparams='yes' is the most common reason why a search shows all products or none.

Search parameters and filter values

The search form passes these parameters in the URL. You can use the same names in the filter attribute, separated by &:

ParameterEffect
searchProducts whose title contains the keyword.
shopProducts of this shop ID (several IDs separated by commas).
manufacturer, brandProducts of this manufacturer or brand.
minprice, maxpricePrice range of the sale price.
minamountsaved, maxamountsavedRange of the saved amount.
orderbySort order: price-asc, price-desc, amountsaved-asc, amountsaved-desc, titlerank-asc, titlerank-desc.
productstatuspublish, draft or all. Without this value only published products are shown if the Frontend Product Pages extension is active, otherwise published and draft products.
productcategoryProducts in these product category term IDs; other taxonomies use their own field name.
product1 to product5Specific product IDs, used by the compare templates.
customfield_<name>, cf_<name>Global custom fields and fields of field groups (dropdown, yes/no; numeric ranges with the prefix min/max).

To show both published products and drafts, use filter='productstatus=all'.

Live search in the shop interfaces

The live search sends the keyword directly to the shop APIs and shows the results on your page. Nothing is imported. Use it with the searchtext form, because the live search only evaluates the keyword. The search runs via AJAX in parallel for every shop.

Results without shop headings

[atkp_livelist template='simple_live' livetemplate='secondwide'][/atkp_livelist]

Results with shop headings

Identical, but each shop block starts with a heading such as "Search results at Amazon".

[atkp_livelist template='default_live' livetemplate='secondwide'][/atkp_livelist]
Live search results from Amazon shown as product boxes with image, Prime badge, price, star rating and buy button
Live search results
AttributeDefaultDescription
templatedefault_livedefault_live with shop headings or simple_live without.
livetemplatewideProduct template for each result. All system templates and your own templates are supported.
shop_idsall shopsLimit the search to certain shops, several IDs separated by commas, e.g. 123,456.
limit10Maximum number of results per shop. Some APIs have a lower maximum that cannot be raised.
filteremptyPreset values in URL format, e.g. category=… for an API category.
elementcss, containercssemptyAdditional CSS classes for the result elements and the container.

Every live search sends one request per shop to its API. Keep an eye on the request limits of your partner programs, and limit the search with shop_ids if you have many shops.

Search form in the sidebar

For sidebars and other widget areas the extension provides the affiliate-toolkit filter widget. Add it under Appearance → Widgets and fill in the title, the target page, the template (for example searchbox or comparebox) and an optional content text. It works like the [atkp_searchform] shortcode.

Create your own search form templates

If you want your own design or want to filter by your own custom fields, create your own search form template. You can also duplicate an existing one.

  1. Go to affiliate-toolkit → Templates and create a new template.
  2. Choose the type Search form template. This type only exists while Frontend Search & Filter is active.
  3. Optionally set the Filter target page and Open result page in new tab.
  4. Build the form with the toolbar above the editor: Containers → Search form inserts the form frame, Form fields the search field, shop, manufacturer, price, order by, product 1 to 4 and the search button, Custom fields your own fields.
  5. Use the template ID in the shortcode: [atkp_searchform template='456'][/atkp_searchform].

The template is written in Blade with HTML and CSS. This example combines keyword, shop and price:

<div class="atkp-searchcontainer">
    <form action="{{$parameters->filtertarget}}" method="get">
        {!! $controlhelper->create_frontendcontrol( null, null, 'search', '', false, $parameters->filterparams ) !!}
        {!! $controlhelper->create_frontendcontrol( null, null, 'shop', '', false, $parameters->filterparams ) !!}
        {!! $controlhelper->get_pricecontrol( $parameters->filterparams ) !!}
        <input type="submit" class="atkp-submitbutton" value="{{$translator->get_search()}}" />
    </form>
</div>

Troubleshooting

The search shows no products

Check that the target page contains a results shortcode and that [atkp_list] has parseparams='yes'. Also check targetpage: it must be the ID of the page with the results shortcode.

Draft products are not found

With the Frontend Product Pages extension active, the search only shows published products. Add filter='productstatus=all' to include drafts.

The live search stays empty

Check the API access of your shops under affiliate-toolkit → Shops. Without a keyword the live search shows the hint to enter a search term.