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
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
thanks - I saw this tip (which is why I references it) but I could not work it out - as my field is a relationship
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...
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
as jquery seems to be useless as a prefilter I will look for another way