Home › Toolset Professional Support › [Resolved] Find MULTIPLE posts by their IDs in one input field?
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 |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10: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/Kolkata (GMT+05:30)
This topic contains 13 replies, has 2 voices.
Last updated by Minesh 9 months, 3 weeks ago.
Assisted by: Minesh.
This https://toolset.com/forums/topic/how-i-can-search-my-posts-by-post-id/#post-1575185
works for ONE post id, how do it for multiple?
How do we have to separate the id values?
Hello. Thank you for contacting the Toolset support.
There is no native way you can add custom search filter (frontend filter) for the post IDs.
The related ticket you shared is workaround.
You should add the following to your view's "Search and Pagination" section:
<label for="post_ids">[wpml-string context="wpv-views"]Post ID[/wpml-string]</label> [wpv-control type="textfield" url_param="post_ids"] [wpv-filter-submit output="bootstrap" class="btn-secondary"][/wpv-filter-controls]
Add the "Query Filter" for the Post ID from your view's Query Filter section as:
Post ID filter Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]
Then, you should add the view as given under:
[wpv-view name="filter-with-postids" ids="[wpv-search-term param='post_ids']"]
To search with multiple post IDs you can separate the post IDs with the comma, for example: 132,555,999 and click on the search button.
Ok, thank you, Minesh.
Only problem is: We don´t want to reload the page each time we wanna filter by IDs.
Our goal is inside a more complex search, to let the user search for HIS/HER posts (IDs saved in a custom user field), besides other search parameters.
So we have to use a URL-parameter, right? This now seems to only work for a SINGLE value.
How do this?
How you are displaying your custom field as filter on the frontend? Is it a select box? textbox or something else?
It´s an input field. Users won´t see it. They just click on "My posts", and jQuery will fill the field.
For input field you must have submit button added to your view to filter the view as without submit button there is no way to filter the view results based on provided input box value.
Ok.
It does work with ONE value in that field.
But with multiple comma separated values, it will always find the first post only.
Adding brackets (post_ids[]) does not work...
Have you added the Query Filter for Post ID as given under:
Post ID filter
Include only posts with IDs set by the View shortcode attribute "ids" eg. [wpv-view name="view-name" ids="1"]
You will have to call the view as given under:
[wpv-view name="your-view-slug" ids="[wpv-search-term param='post_ids']"]
shortcode won´t work with AJAX, right?
We want the user to be able to check if he only wants to see HIS/HER posts and then search results should be updated by AJAX accordingly.
shortcode won´t work with AJAX, right?
==>
Yes - that's correct.
We want the user to be able to check if he only wants to see HIS/HER posts and then search results should be updated by AJAX accordingly.
==>
There is no other way as there is no such feature available even to filter posts by post ID but if you would like you can use the shared workaround. If not - there is nothing much we can do, I'm afraid.
So there is no way to let users search for their favorite posts in an AJAX search?
Or do you have an idea how you would do it?
Does it take /much) PHP?
Or maybe, just copy the post ID to a custom field at post creation and then search for that field?
So there is no way to let users search for their favorite posts in an AJAX search?
Or do you have an idea how you would do it?
Does it take /much) PHP?
===>
Maybe you can store the favorite posts post IDs while creation of posts and add a checkbox filter and if its checked then you can show favorite posts otherwise not. This is just idea I'm not sure if thats exactly your requirement but you can check and test.
You may have to use the "wpv_filter_query" hook.
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Or maybe, just copy the post ID to a custom field at post creation and then search for that field?
===>
Yes - you can try that but you have to decide do you want to have multiple instance field that holds the post ID or comma separated post ID in one singular text field..
You can check and select as per your requirement.
Or maybe save the USER-IDs, whose favorite a post is, in a post´s custom field like " 1 127 453 76 ..." and then text search for " USER-ID "? Then one would have to display a little form in each post with USER-IDs and manipulate that by JQUERY. Would that take very much resources?
Or maybe save the USER-IDs, whose favorite a post is, in a post´s custom field like " 1 127 453 76 ..." and then text search for " USER-ID "? Then one would have to display a little form in each post with USER-IDs and manipulate that by JQUERY. Would that take very much resources?
===>
I cant say much as I already acknowledged that there is no native feature available to add a custom search with post ID. Rather than what you shared what I shared would be more efficient and easy for you as per my perspective.