Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Default Dropdown item as a custom field › Reply To: Default Dropdown item as a custom field
Hi,
Might be possible, but definitely requires some custom coding. If I understand correctly, you want to select a default category depending on which page is displayed.
I constructed a small custom code snippet, which may help you with that. All you need to change/add is the $select_category variable. It is an array of items, each line represents one page ID and the default selected category ID.
I have added two lines to help, one line one, this code will try to select category ID = 321 whenever the page with the ID = 123 is displayed – also for page ID = 124 it selects category ID = 421.
Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_filter('asp_pre_get_front_filters', 'asp_change_a_filter', 10, 2);
function asp_change_a_filter($filters, $type) {
$select_category = array(
123 => 321, // Page ID -> Default Selected Category ID
124 => 421
);
// Do not change anything below
foreach ($filters as $k => &$filter) {
if ( $filter->type() == 'taxonomy' ) {
if ( is_singular() && isset($select_category[get_queried_object_id()]) ) {
$filter->attr($select_category[get_queried_object_id()], 'selected', true);
}
}
}
return $filters;
}