home-icon
Search function
Last updated: Mar 18, 2024

Introduction

The Webigniter connector has a builtin search function. with this function you can search for pages and content within specific categories or across the entire site.

Usage

In order to create a search function on your page, use the $webigniter->searchPages(), method.

This method allows 2 parameters, the search query and an optional array of categories, the search function will only search in the specified categories, and if none supplied across all categories.

<?php foreach($webigniter->searchPages('example', [4944]) as $searchResult):?>
   <a href="/<?=$searchResult['link'];?>"><?=$searchResult['category'];?> - <?=$searchResult['title'];?></a>
<?php endforeach; ?>

This example wil search within all pages and subcategories within the specified category ID for the term 'example'. In the foreach loop all results are looped. Within this loop you will have a  'link', 'category' and a 'title' at your disposal, where category is the name of the category the page is in.

To find the right category ID, navigate to your category in the CMS. The number at the end of the URL is your category ID.

Table of Contents
  1. Introduction
  2. Usage