Skip Navigation

[Resolved] In one view search input reasearch two Content Type post

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.

Our next available supporter will start replying to tickets in about 8.54 hours from now. Thank you for your understanding.

This topic contains 4 replies, has 2 voices.

Last updated by darioM-3 1 month, 3 weeks ago.

Assigned support staff: Christian Cox.

Author
Posts
#2125295

Tell us what you are trying to do?
Hello support,

A quick explanation of what I want.

The first step which works:
I have a custom post type called: Bikes.
I want to research the title of Bikes and display it in my view.
I try to make a custom view with one search input "inputs from Frame Number".
On that search input field, I want to put the text input of a custom field called: Frame Number which belongs "Bikes" like custom post field and that work fine when I research Bikes (display the good result)

The second step which not work:
I make a second custom post type called: Sticker ID
Now what I want it is that also when put in the same search input field title of Sticker ID (like where it is Frame Number inputs) also to get research of the Bikes as I get exactly like I put Frame Number text input. I also make the relationship between Sticker ID and Bikes posts, but I don't get on search what I want.

Is it possible to make that research in one search input field or need to be separated?

Is there any documentation that you are following?
I not found

Is there a similar example that we can see?
https://toolset.com/forums/topic/custom-search-across-two-post-types-enabling-user-filter-to-select-one-or-other/

Maybe this link can be an example, only to be one custom search input, not two tabs like there.

What is the link to your site?
It is on localhost. I can put it online if needed.

#2125409

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Hello, unfortunately there is no built-in way to make one search filter search the contents of two separate custom fields in Views. The only built-in way to make this work is if both post types use the same custom field to store their field values. For example, you would create a new Field Group and apply this field group to both Stickers and Bikes post types. Then in this new field group, you would create a custom field "Frame Number or Sticker ID". In your Bike and Sticker posts, you would place the Bike's Frame Number or the Sticker's Sticker ID in this field. Then in the search View, you would create one search filter based on this new field. This would allow you to search the contents of both post types with one search input using built-in Types and Views features.

Any other solution would require custom code that manipulates the search query. We have some PHP APIs available if you are comfortable writing custom code to manipulate WordPress queries, for example wpv_filter_query:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Let me know if you have questions about this and I can try to provide additional information.

#2125619

Hello support again,

Maybe you do not understand me well. I don't need one search filter to search the contents of two separate custom fields or custom types in Views.

What it exactly need I give you a real example:

1. I want to put in the search field "Bike Frame" number and get the title (or some of the content) of the Bikes in my View.
2. I want to put the title of my Sticker ID (Custom post separated but have a relationship with Bike) in the same search field as it is for "Bike Frame" to get also the title (or some of the content) of the Bikes in my View which connected.

I hope that now is much more clear for you or I dismiss something there? 🙂

#2125645

Christian Cox
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Okay I think I understand better. Sticker ID is the name of the related post type, not one of its custom fields. It sounds like you want to be able to search for Bikes by Bike Frame number or by Sticker post title using the same custom field filter. Unfortunately this is not possible in native Views, there is no built-in way to combine one search filter to search both by custom field in post type A and by related post title in post type B. You would have to use two separate input fields to create a custom search like this - one for searching by Bike Frame Number, and another for searching by related Sticker ID post. There is no built-in way to achieve both types of filters in a single field.

#2125669

Hello Christian again,

I try the option with two custom search fields so I make that My issue is resolved now.

Thank you a lot for yours time!