Hi,
you can set default value for advert_category field by adding the code below in your theme functions.php file
add_action( "adverts_form_bind", "default_value_for_adverts_add", 10, 2 );
function default_value_for_adverts_add( $form, $data ) {
if( ! isset( $data['advert_category'] ) ) {
$form->set_value( "advert_category", 25 );
}
return $form;
}
Just replace 25 with actual ID (numeric) of the taxonomy you would like to use as a default.
ok, I see I wasn’t clear; my bad.
anyway, what I want to achieve is to set the categpry to none and not leave the user to post advert until he sellect a category.
-
This reply was modified 7 years, 11 months ago by
wpusrnm.
Ohh ok, in this case you will need to use a different code
add_filter( "adverts_form_load", "single_select_advert_category" );
function single_select_advert_category( $form ) {
if( $form['name'] != "advert" ) {
return $form;
}
foreach( $form["field"] as $key => $field ) {
if( $field["name"] == "advert_category" ) {
$form["field"][$key]["empty_option"] = true;
$form["field"][$key]["max_choices"] = 1;
$form["field"][$key]["validator"] = array();
$form["field"][$key]["validator"][] = array(
"name" => "max_choices",
"params" => array( "max_choices" => 1 )
);
}
}
return $form;
}
thanks man, that solved it!
just in case someone wants to implement it.
you must set the filter that makes the category required after this one.
big thanks!!!
-
This reply was modified 7 years, 11 months ago by
wpusrnm.