Skip Navigation

[Resolved] set default value of a view filter which is a relationship field

This support ticket is created 6 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by bryan 6 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1148011

Tell us what you are trying to do?

set default value of a custom search field (which is a relationship field)

In this simplified example I have Custom Posts with relationships

Rogues
...who are members of
Rogue Clubs

I can set a view with a custom search to filter the Rogues based on the rogue club they are in; but I would like to set the Default value of the club to NONE so no one displays until a club is selected.

I found a tip about JQuery which is similar but I cannot figure out if(and if so how) this works for relationship fields ?
https://toolset.com/forums/topic/how-to-prefill-default-value-in-dropdown-box/

Here is my trivial sample filter

[wpv-filter-start hide="false"]
[wpv-filter-controls]
[wpv-control-post-relationship ancestors="rogue-clubs@rogue-club-rogue.parent" url_param="wpv-relationship-filter"]
<div class="form-group">
<label>[wpml-string context="wpv-views"]Rogue Clubs[/wpml-string]</label>
[wpv-control-post-ancestor type="select" ancestor_type="rogue-clubs@rogue-club-rogue.parent"]
</div>
[/wpv-control-post-relationship]
[/wpv-filter-controls]
[wpv-filter-end]

and content is simply showing a photo and a name

[wpv-post-title]
[types field="hs-photo"][/types]
[types field="name-of-rogue"][/types]

CPT info
the slug for rogue clubs is
rogue-clubs

thanks

#1148064

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Bryan,

Thank you for contacting our support forum.

So what I see here is that you want your parent field to have a default selection.

jQuery(document).ready(function($) {

jQuery("select[name^='YOUR-SELECT-NAME'] option[value='OPTION-VALUE']").attr("selected","selected");

});

The code above should be able to help, however you need to add the appropriate selectors for the field.

Thanks,
Shane

#1148238

thanks - I saw this tip (which is why I references it) but I could not work it out - as my field is a relationship

#1148239

the reasons I went to the trouble of making an example and sending all my view code exactly so I didn't just get sent back the tip I already found...

#1148918

Using a simple (non relationship field) I was able to pre-fill but not pre-filter the results - so I am guessing jquery is not the way to go

#1148925

as jquery seems to be useless as a prefilter I will look for another way