Skip Navigation

[Resuelto] Find MULTIPLE posts by their IDs in one input field?

This support ticket is created hace 10 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 13 respuestas, tiene 2 mensajes.

Última actualización por Minesh hace 9 meses, 3 semanas.

Asistido por: Minesh.

Autor
Mensajes
#2679012

a.R

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?

#2679050

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2679065

a.R

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?

#2679066

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

How you are displaying your custom field as filter on the frontend? Is it a select box? textbox or something else?

#2679073

a.R

It´s an input field. Users won´t see it. They just click on "My posts", and jQuery will fill the field.

#2679075

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2679100

a.R

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...

#2679104

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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']"] 
#2679230

a.R

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.

#2679394

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2679579

a.R

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?

#2679594

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2680364

a.R

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?

#2680396

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.