Skip Navigation

[Resolved] How i can search my posts by post ID?

This thread is resolved. Here is a description of the problem and solution.

Problem:

Add a "Post ID" input box into the search form, and use it search the results by post IDs.

Solution:

There is a workaround, for example:

https://toolset.com/forums/topic/how-i-can-search-my-posts-by-post-id/#post-1575185

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-control

This support ticket is created 4 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Rostislav Avtodiychuk 4 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1574157

Tell us what you are trying to do?
Hi, i have many post in my custom post typy and my users need automatic identificator for each of them, the order doesn't matter. And they need search post by this unique number.
I thought that the post-id is the best solution for my case, but I came across the fact that searching by post-ID does not work in filter in view.
I found a suggest on the forum that you can suggest create a custom field and assign it the post-id value and then can display the search filter for my custom field. But unfortunately I didn’t understand how to do it better. I tried to set a condition, but nothing worked for me. Help with any advice. Thanks.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1575185

Hello,

I assume you are going to a "Post ID" input box into the search form, and use it search the results by post IDs.

If it is, there isn't such kind of built-in feature within Toolset Views/Blocks plugin, but there is a workaround, for example:
1) Edit your post view, in section "Query Filter", add a post ID filter:
Include only posts with IDs determined by the URL parameter "post_ids" eg. yoursite/page-with-this-view/?post_ids=1

Above filter will be able to use URL parameter "post_ids" to fitler the result.

2) In section "Search and Pagination", display the search input box like this:

...
<label for="post_ids">[wpml-string context="wpv-views"]Post ID[/wpml-string]</label>
[wpv-control type="textfield" url_param="post_ids"]
...

Above shortcode will display a single line input box, and pass URL parameter "post_ids".

More help:
https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-control
This shortcode will output filter controls for your custom searches.

#1575235

My issue is resolved now. Thank you! Love toolset!