How to Assign Ajax Search to the Current Query Listing Grid

Learn how to assign the Ajax Search to the specific Listing Grid with the help of JetSearch and JetEngine plugins for WordPress.

Before you start, check the tutorial requirements:

  • Elementor (Free version) or Block editor (Gutenberg)
  • JetSearch plugin installed and activated
  • JetThemeCore plugin installed and activated
  • JetEngine plugin installed and activated with the Listing(s) built

Things to know

This use case is based on the BaliRento dynamic template.

Build a Query

Initially, let’s build a query for the listing that will be displayed on the archive page. To do it, proceed to the WordPress Dashboard > JetEngine > Query Builder and press the “Add New” button.

Name the query (here, “Properties Current Query”) and set the Query Type to “Current WP Query”.

Press the “Add new page type” button in the Posts per page block of the Current WP Query section.

general settings section of the current wp query in the query builder

Pick the name of the post type you work with in the Page Type dropdown (for example, we select “Properties.”)

Also, specify the Posts number that will be displayed later in the listing.

current wp query section in the query builder

Ultimately, press the “Add Query” button.

Then, we want to add another query that will be used for the second listing displayed on the search page. To do so, proceed once again to the WordPress Dashboard > JetEngine > Query Builder and press “Add New”. 

Give a name to the query (here, “Properties Query”) and select the Query Type (here, the default “Posts Query”).

general settings section in the query builder

Next, we select the Post Type that will be displayed in the listing. Here, we select the “Properties” option.

Also, we press the “Add new sorting parameter” button, select the “By title” option in the Order By field, and the “From lowest to highest values (1, 2, 3; a, b, c)” option in the Order field.

general tab of the posts tab

Next, we also head to the Pagination tab and specify the “3” value in the Posts Per Page field so only three posts will be visible in the listing.

pagination tab of the posts tab

When the query is ready, press the “Add Query” button.

Create an Archive Page

Next, you should build an archive page for the post type you work with if you haven’t done it before. It can be done with the help of the JetThemeCore plugin.

Go to WordPress Dashboard > Crocoblock > Theme Builder and press the “Create new page template” button.

In the appeared window, press the “Add Condition” button to specify the conditions. 

Select the “Include,” “Archive,” and “All (Your post type name) Archive” options and click the “Create” button.

create page template conditions

You can set the header and footer if desired by pressing the “Override theme header/footer” buttons.

However, we will focus on the template’s body, so let’s set it right away. To do so, click the “Override theme body” button.

In the opened menu, select either the “Create template” button to build a template from scratch or the “Add from library” button to pick the previously created template from the list. In our case, we push the “Create template” button.

create template and add from library buttons in the theme builder

Set the template’s name (optional) and select the preferred editor (here, we pick “Elementor”). Then, press the “Create” and “Go to editor” buttons.

create a template pop-up

In the editor, we first add a Heading with the “Search results:” text to indicate that the following listing will contain the search results.

the first heading

Add the Listing Grid widget/block to the page. 

Select the recently created Listing in the corresponding field (here, “Properties Listing”).

general tab of the first listing grid

Head to the Custom Query tab and activate the Use Custom Query toggle. 

Pick the previously built query (in our case, “Properties Current Query”) in the Custom Query dropdown list.

custom query tab of the first listing grid

Then, proceed to the Advanced tab and complete the CSS ID field with the desired value, which will later connect this listing with the Ajax Search. For instance, “listing-grid-1”.

Adjust other widget settings as well if needed.

advanced tab of the first listing grid

Next, we add one more Heading to the page. This time with the “We recommend:” text.

the second heading

Then, we add one more Listing Grid widget to the page. 

Select the desired Listing in the corresponding field. For example, we select the same “Properties Listing.”

In the Custom Query tab, we select the “Properties Query” that we have built before for this listing.

custom query tab of the second listing grid

Next, we proceed to the Posts Query tab. You can adjust any other query for this Listing Grid except the “Current WP Query” one in the Custom Query tab.

Here, we press the “Add Item” button and select the “Meta Query” Type. The Key (name/ID) is set to “top” here as it is the “Radio” meta field’s Name/ID, the Operator is set to “Equal”, and the Value to “yes”. So, only those posts that have the “yes” option selected in the “Top” meta field will be shown in the Listing Grid.

posts query tab of the second listing grid

Adjust other widget settings if needed and save the page by pressing the “Publish” button.

Add a Search Page

Navigate to the WordPress Dashboard > Pages directory and create a page by clicking the “Add New” button or selecting an already existing page.

Add an Ajax Search widget to the page.

search form tab of the ajax search widget

Paste the search results URL into the Custom Search Results URL field. Also, specify the Listing Grid’s ID in the Target Widget ID (optional) field. Here, “listing-grid-1”

Make sure that the Source used for the Listing Grid and the Ajax Search is the same.

custom search results url and target widget id fields

Customize the widget and page additionally if needed, and press the “Publish” button.

ajax search style settings

Check the Result

Head to the page where the Ajax Search is located.

Enter your request in the search input area and press the “Search” button.

ajax search on the front end

Now, you will be redirected to the “Search Results” archive page. Here, you will see only the first listing filtered, which is the needed one.

the first listing on the front end

The second listing will be left as is.

the second listing on the front end

That’s all about assigning an Ajax Query to the Listing Grid Current Query to limit search results on the archive page with the help of the JetSearch plugin for WordPress.

Facebook
Skype
Twitter
LinkedIn
Pinterest
WhatsApp
Print
Threads
ABOUT AUTHOR
Rabby Islam

WordPress Web Developer | Loves To Coding & Explore new Things!

ADVERTISEMENT