Help Center
How to Search Posts by IDs

How to Search Posts by IDs

Discover how to search posts by their IDs with the Ajax Search from the JetSearch plugin.

Before you start, check the tutorial requirements:

  • Elementor (Free version), Block editor (Gutenberg), or Bricks

  • JetSearch plugin installed and activated

  • Code Snippets plugin (free version) installed and activated

You can adjust the search to be conducted by post IDs by following the path described in this tutorial.

Add a Code Snippet

Go to WordPress Dashboard > Snippets > Add New.

Give the snippet a title. For instance, we have entered “Search by IDs” in the title field.

Put the following code in the Code section:

add_filter( 'jet-search/ajax-search/search-by-post-id', '__return_true' );

Once done, press the “Save Changes and Activate” button.

Things to know

Alternatively, this code can be added to the “functions.php” file of the active theme.

add new snippet directory

Add Ajax Search to the Page

If you haven’t put the search on the needed page/template, navigate to its editor.

For instance, we go to WordPress Dashboard > Crocoblock > Theme Builder and press the “three dots” and “Edit content” buttons next to the built header.

Things to know

The provided functionality is accessible if you have the JetThemeCore plugin installed and activated. However, it is not required in the described case; you can add Ajax Search to other pages/templates built with Elementor, Gutenberg, or Bricks.

theme builder directory

In the opened editor, add the Ajax Search widget/block/element to the page.

Learn more about How to Add an AJAX Search to a Website’s Header.

Things to know

Also, pay attention to the picked Source in the Search Query tab as the search will be conducted among the posts of the selected source.

ajax search in elementor

Adjust its settings and click the “Publish/Update” button to save the changes.

Check the Result

Head to the front end page. In our case, it is the home page, where the search is located in the header.

Complete the search field with any post ID to check if everything works correctly.

Now, we can observe that the results preview shows the needed post.

result on the front end

That’s all; now you know how to search posts by their IDs with the Ajax Search widget/block/element available with JetSearch for WordPress.

Was this article helpful?
YesNo

Need help?

Ask Facebook community

Get answers from 22K Crocoblock Community experts from all over the world.

Start a live chat

Ask question to support agent and share its details via chat messages.