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.
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.
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.
Adjust its settings and click the “Publish/Update” button to save the changes.
Check the Result
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.