Skip Navigation

[Resolved] Need to Filter wpv-control-postmeta to only show a drop down realated to parent

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

Problem:

How to filter search dropdown items limited to the repeatable field?

Solution:

Toolset does not have that filter feature. You can use the workaround below:

- Add a view that lists the repeatable field items and add them as an HTML hidden field.

- Add the custom JS below to the content template that you use to replace the content of the search dropdown with the hidden fields:

jQuery(document).ready(function() {
    var theTracks = '<option value="" selected="selected">Choose a track</option>';
    jQuery('#track-options > input').each(function(){
        theTracks += '<option value="' + jQuery(this).attr('value') + '">' + jQuery(this).attr('value') + '</option>'       
    });
    jQuery('select[name="wpv-wpcf-track-name"]').html(theTracks);    
});
This support ticket is created 3 years, 1 month 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.

This topic contains 9 replies, has 2 voices.

Last updated by cameronJ-3 3 years, 1 month ago.

Assisted by: Christopher Amirian.

Author
Posts
#2337825
Screen Shot 2022-04-09 at 12.56.33 PM.png

Tell us what you are trying to do?

Hello, i would like to filter [wpv-control-postmeta type="select" field="wpcf-track-name" default_label="Choose a track" url_param="wpv-wpcf-track-name"] to only show track names related to the parent "Trail" post.

I tried adding the relationship to the query filter but it still shows up in the dropdown options.

What is the link to your site?
hidden link

#2338273

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Would you please give context on your setup?

Kindly give me the way relationships are set up and what are the custom fields and how you want the select values filled so that I can grasp a better idea of the setup.

If you can provide a small implementation here it is even better so I can see the results:

hidden link

Thank you.

#2338311

Implementation complete. If you check out this page: hidden link you will see the elevation section of the page. I would like the filter dropdown options to be limited to only the child tracks of the trail post. For example, on the Seguin trail page there should only be an option for "Forks of the Credit" because it is the only track in the field group for that trail.

The demo site has been setup with all of the custom fields as you requested above.

Thanks,
Cam

#2338625

Christopher Amirian
Supporter

Languages: English (English )

Hi Cam,

Thank you for the demo. I checked the details and I can not understand what is the common option between "Forks of the Credit" and "Seguin Trail - Horseshoe Lake Road to Orville".

Where did you set them to be a child or any kind of relashion? The issue is that I do not see any common thing between them other than they both are trails.

Thanks

#2338807

Sorry I accidently put the forks of the credit track in the Seguin trail. It has been fixed.

There is no relationship between the seguin and forks of the credit trail.

Please let me know if this helps or if you need more information,
Cam

#2339663

Christopher Amirian
Supporter

Languages: English (English )

Hi Cam,

The issue that I have understanding your implementation is that I am not sure how you set a track post item to be the child of another one. I am confused on the implementation.

I see no connection between the post items that is why I am not sure why the search dropdown should not show a post item and should show another one.

#2339683

Hey Again,

The Track is a repeatable group field within the trail post type, the relationship is that the trail post type is the parent of the track because the repeatable group is inside the trail post type. I want the dropdown to only show the repeatable group fields from the single trail post and not all of the trail posts.

I know this does work because I am able to put a query filter to only show repeatable groups from that trail, but for some reason the it does not apply to the dropdown and still shows all of the repeatable group fields for all trails and not the single trail post that you see on the frontend.

For Example,
The "Forks of the Credit Road" trail post only has one track, called "Forks of the Credit Fixed". When you go to the trail page ( hidden link ) the elevation dropdown should only show "Forks of the Credit Fixed". It is currently showing tracks from the other posts like "this track is from island lake, this track is from test 3, and this track is from test 4", and shouldn't be.

I hope I explained it better now.

Thanks,
Cam

#2340455

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

Thank you for the info, I think I now understand the problem. I asked for a second opinion and will get back to you.

Thanks

#2340469

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I double-checked and the issue is that Toolset does not have such a filter per post when there is a repeatable field.

There is a workaround that I implemented in the clean installation which is just a workaround and is not a feature so whatever you see is as is and if you need further features you will need to ask for a feature request here:

https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

Now the workaround:

If you check here:

hidden link

I added a view, in that view, I just listed the track names for the current post that will show.

In the content template:

hidden link

I added the view after your view. My view adds the track names as an HTML hidden field in the page.

If you check the sidebar of the content temp[late I added the Javascript code below:

jQuery(document).ready(function() {
    var theTracks = '<option value="" selected="selected">Choose a track</option>';
    jQuery('#track-options > input').each(function(){
        theTracks += '<option value="' + jQuery(this).attr('value') + '">' + jQuery(this).attr('value') + '</option>'        
    });
    jQuery('select[name="wpv-wpcf-track-name"]').html(theTracks);    
});

What it does, is to get the options from the hidden field and replace it with the default search select options of Toolset.

Now if you check the single post you will see the items show the relevant track names:

hidden link

I added another track to the trail post to make sure it works ok. (blabla)

Thanks.

#2340875

Thanks Christopher, your fix works perfectly!