I am trying to:Set a default value for for States
I visited this URL:-
I expected to see:-
Instead, I got:-
Dear cemcildir,
The select dropdown field "State" is using Views shortcode [wpv-control-set], for example:
[wpv-control-item type="select" ancestor_type="state" default_label="-- State --"]
If the are going to change the text of default option "-- State --", you will edit the attribute "default_label" as what you want.
If you are going to setup the default value of field "State", according to our document:
https://toolset.com/documentation/views-shortcodes/#wpv-control-item
There isn't such an option to setup the default value.
But you can pass it with URL parameter, for example:
hidden link
user/pass: xgren/111111
It will setup the the "State" dropdown as default value "428", which is "Arizona"
Dear Luo,
I was hoping for the second solution to have an option for a default value,because the third solution forces my homepage url to look cluttered.
Bad-->hidden link
Good-->hidden link
Is there a way to have the functionality above with the url of below?(I guess a .htaccess query string redirect?)
Thanks
Cem
Can you be more specific?
For example, we can setup the "Arizona" as default value, you can try this:
1) Add below codes into your theme/functions.php:
add_shortcode('default-state', 'default_state_func');
function default_state_func($atts, $content){
$atts = shortcode_atts( array(
'state' => 428,
'url_param' => 'wpv-pr-child-of-state',
), $atts);
if(!isset($_GET[$atts['url_param']][0]) || $_GET[$atts['url_param']][0] == ''){
$_GET[$atts['url_param']][0] = $atts['state'];
}
return;
}
2) Edit the archive page:
hidden link
put the shortcode [default-state] just before the Views shortcode
[wpv-view name="search-house"]
Hi Luo,
I can't access your demo site(see image)
hidden link
using user/pass: xgren/111111
I am using the layout version of Real Estate so I thought the shortcode should go to the
"Search - House" View but there isn't [wpv-view name="search-house"] shortcode?
Sorry, I just setup the user "xgren" as admin user of above test site, please test it again.
Dear Luo,
I think I am on the "Layout" version of Real Estate and your test site isn't.
So I do not know where to put [default-state] since there is no
[wpv-view name="search-house"] shortcode 🙁
You can simply create a content template cell to replace the Views cell, and put above custom shortcode and the View's shortcode into it
Dear Luo,
I guess it would work that way but I have decided that I don't need that function any more so you could say that my problem's solved.
Thanks