Skip Navigation

[Resolved] Ability to set default value for fields

This support ticket is created 6 years, 2 months 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
- - 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)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Beda 6 years, 2 months ago.

Assisted by: Beda.

Author
Posts
#1094848

Hello,

I have several fields within a custom search and want to set a default value. Best option would be the shortcode.

All fields are URL param fields. I know I could link to the url, but I don't want to create individiual links in menus, but use the ability to link to existing pages.

Is this possible somehow?

Thanks,

Adrian

----
I came accross this: https://toolset.com/forums/topic/how-to-set-default-value-of-radios-filter-in-view/
But this is also not a solution as it triggers a custom search, directly after the user comes to the page.

#1095636

If you do not need those as "Search values" to be triggered when the user loads the page - then those would be more "placeholders" than "default values".

However, if you select a certain option in a filter, supposedly it should return some results, otherwise, we would call such a search broken.
That means the only solution here I see is to use a Search that does load it's results upon the search submit button is pressed and alters it's checked state of the filters with JS when the page loads (so it does not affect the URL just yet, since it is not passed to the URL yet, only to the inputs).

Now, if you use a Text Search input, you can set such placeholders.
The code generated by the GUI for a simple text input search with placeholder:

<div class="form-group">
	<label>[wpml-string context="wpv-views"]afsd[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-afsd" type="textfield" url_param="wpv-wpcf-afsd" placeholder="Placeholder (could be real value as well, but will not be passed as such)"]
</div>

You can do that similarly for Radio inputs:

<div class="form-group">
	<label>[wpml-string context="wpv-views"]afdsadfs[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-afdsadfs" type="radios" default_label="Default Option that you can customize (but has no value, it is similar to the ALL option in a radio or select field)" url_param="wpv-wpcf-afdsadfs"]
</div>

Would this help you to achieve your goal?
You cannot select an existing value without loading those results, but you can create a custom placeholder for text or a custom "first option" for radios.

This can all be set when you use the GUI for "New Filter" in the Search and Pagination section of a View (no need to edit the HTML above manually, you can generate it with the GUI)

#1095689

Hello Beda,

Thank you, but this is not exactly what I want.

What I want:

A mix of the field configuration: URL param and Shortcode

Means:

I want to use the shortcode and set a default value like [wp-view param1="House"] and still give the user the option to alter this filter in the frontend (and then be able to save the URL like ?param1=House).

-> processing order

1. If url param is set -> use this
2. If shortcode param is set -> use this
3. else default behaviour.

I wonder why it is not possible to mix url params and shortcode params or just define a default selection within the filter configuration.

Background: we want to build multiple prefiltered landing pages using the same filter but without the need to use url params (to have "clean" urls).

Thank you,

Adrian

(Anyway: great plugin)

#1096764

I do not understand.

Previously you mentioned, triggering a custom search, directly after the user comes to the page, is not the goal you have.
https://toolset.com/forums/topic/ability-to-set-default-value-for-fields/#post-1094848

If the goal you have is to set a value in the (any form of) input filters of the View, that actually "has an effect" on the results, but not populating the URL attribute with a custom link to the view (passing the default attribute), you could maybe work with this method:

- When creating the filter, choose either "Select Dropdown", "Select Multiple", "Set of Radio Buttons" or "Set of Checkboxes".
- Then select "Using Manually Entered Values"

Now you have to match existing values, but can change the labels as you like, and make the View load at the beginning one certain default option (just drag it to the first row of options you add)
An empty value is equal to "all".

You cannot mix 2 Query Filters as you mention (Shortcode AND URL) over the same data.

But the above steps should produce a similar result.