Sauter la navigation

[Résolu] How to select a Related post value from the custom search?

This support ticket is created Il y a 5 années et 11 mois. 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Ce sujet contient 6 réponses, a 2 voix.

Dernière mise à jour par Beda Il y a 5 années et 11 mois.

Assisté par: Beda.

Auteur
Publications
#1204555

I am trying to Build a custom search about Profile CPT posts. The Profile CPT have a relationship with Città CPT, where the user when creating his own Profile CPT post, he can select the Città CPT related to display the map on his Profile CPT post.
Than, now, I need to set the search by maps or distance, but I don't know how the maps and distance forms can read the map values from the Parent Città CPT posts...

Link to a page where the issue can be seen: lien caché

I expected to see: the text form, like as Form text input to select the city, with a suggestion list from the Parent Post Relationship about the maps search form.

Instead, I got: Nothing...

#1204941

Related Posts can only be searched in a View by one "parent" tree.
This means, you have for example one Post Type A and a related Post Type B - you can list Post Type A in the View, and add a Custom Search for Post Type B it is related to.

This allows not to query by a distance to that post types fields or addresses, as that would mean to query by related posts fields.
This is something not possible in Toolset (to query by fields of related posts) and you would have to suggest it as a new feature here:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

To get a text Field with a suggestion is also something not possible in Toolset.
You can have a text Field input that searches by the value you input, but it will not suggest existing values.
That would as well require a new feature to be added.

To have a Custom Search for fields of the post queried where the user can choose existing values, the best is a select or checkboxes search input.

#1205008
select-city.png

Thanks for your reply.

I'll write my suggestion soon.
But, to have what I need, can I create a Custom Filed into Profile CPT post, where when the author select his City Parent Post, to add his generic localization in post, the Parent Post value (the title, or the maps value) will be saved in the Profile CPT Custom Field?

Too see what I need to have to select the City in the Custom Search, see the attached image. And so, it is possible to have that? Because I have up to 8000 items, and a simple select or checkboxes search input I think have some difficult to display all value!!!

#1205073

Hi, I have tried to do that:
I have created a View where I take the title of the City CPT parent Post.
I have created a Custom Field "City" into the Profile CPT posts, I have tried with two fields, the first time with the address field and second time with the text field.
In the Form to modify the single Profile CPT posts, I have added this code in a hidden div:

[cred_field scaffold_field_id='citta-profilo' field='citta-profilo' force_type='field' class='form-control' output='bootstrap' label='Città' value='[wpv-view name="citta-per-crea-e-modifica-profilo"]']

but it don't save the value in the field... but if I try to display it only using this shortcode

[wpv-view name="citta-per-crea-e-modifica-profilo"]

I can see the Parent post title.....
What is wrong, and what should I do to have what I need?

#1206184

What you show here is like a Select2 and we offer that only with the relationship features (Post relationship and Reference)
You cannot make any other Toolset Field be like that (Select2).

I totally understand the requirement, but it is possible only with the Post Relationships features or Post Reference Features, and those are later only searchable by ONE relationship tree a time (as elaborated previously).

Now, what you tried in the reply here https://toolset.com/forums/topic/how-to-select-a-related-post-value-from-the-custom-search/#post-1205073, is related to the Toolset Forms only.

There, in a generic field, if of type Checkboxes, Select or Radio, you can use a ShortCode to populate the options.
That can also be a View ShortCode, but in that case, you would need a "raw" view.
A "raw" View needs to be made by checking the checkbox below the View Loop Output editor "Disable the wrapping DIV around the View".
Normally, the View has a wrapper DIV which includes IDs and classes required for AJAX updates and pagination. If you want to show the View inline with text, you can disable this DIV, but you will not be able to use some of the functionality that Views offer.

Then, the View's loop needs to follow the precise JSON standard as explained in the Forms Generic Fields hint where you choose to add a ShortCode instead of the hardcoded values.

I think checking that box and ensuring the JSON syntax will solve the issue with the Field not populated, however, note that Generic Fields do not save.
They save only if you add the deprecated "persist:1" to it, or apply custom code on cred_save_data() to save them to the database.

#1207317

Thanks for your reply.
So, I'm not happy to use Toolset and View for Custom Search.
So, I think that it should be logic to add a function to search posts about their parent, grand parent, grand grand parent, grand grand grand parent posts about the relationship.
Or to have a simple solution to do that.
So, I have "Disabled the wrapping DIV around the View" but no value was saved, and I don't know how I can use "persist:1" or I can apply custom code on cred_save_data() to save them to the database... and I don't know what custom code I can use to save dynamically the Various Parent and Grand Parent Posts Title or maps field, into the relatives fields into the child posts.

And I think also that it should be logic to use the "Select2" when the fields are more populated...

Now, without those features, I cannot continue with this work and all the time that I have spent on it is a lost time...
I am angry because I don't have a solution and you tell me that there isn't a solution...

#1207600

Well, you can of course search by parent (related) posts in Toolset, but only by one tree a time.

For this you create a View, query the one end (Child) and then add a new Custom Search (by post owner/post relationship) and choose the other end as the search (parent)

Please head to create a new View or edit an existing view where you query the post type in question, to see what I mean, in the Filter and Pagination section.

The issue you mention about filtering is not related to a select2 field where a user is able to pick any post of any type that is added to it, those are 2 different aspects of the Toolset, one is possible (Parent post filtering by one tree) - the other, adding a Front End Search field of select2 type, is not possible.

If you instead plan to populate a Forms Field (generic select - which is also not select2) with a View's shortcode (View returns valid JSON), then that is another topic again.
This happens in Forms, and you could not use a Custom Search for the View that populates that Field, as it must already return the results in JSON format, hence, you would need a Query Filter in the View, which restricts the posts by a parent tree, for example. But again this would be possible only by one tree a time.

Please let me also reply to your other doubts below:

1. So, I have "Disabled the wrapping DIV around the View" but no value was saved

I think this is because of an outdated Toolset views Plugin.
Please update Toolset and try again, as it is solved in the latest release.

2. and I don't know how I can use "persist:1"

This is as said deprecated and I feel I should not inform how to use it, however, it is used like this:
https://toolset.com/forums/topic/cred_generic_field/#post-166826
You add persist:1 to make the field save to the database.
This will not add a Toolset Field but a simple WordPress Custom Field, to the post edited or created with the Form.
It can be used in Custom Search of View later, or displayed with the wpv-post-field shortcode, if needed, but is a simple field only.

3. I can apply custom code on cred_save_data() to save them to the database

Please find an example of this here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data > More Usage examples

4. And I think also that it should be logic to use the "Select2" when the fields are more populated...

Please use this form to submit a suggestion to the Plugin Product Manager:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

Please let me know if you require more details, I can help to eventually find other solutions, if possible.