Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Default Dropdown item as a custom field
- This topic has 3 replies, 2 voices, and was last updated 4 years, 4 months ago by
Ernest Marcinko.
-
AuthorPosts
-
November 19, 2021 at 8:48 am #35639
tharindu63
ParticipantHello
https://simplisurety.com/states/california-surety-bonds/I am creating these pages for all the states but I want to keep a single search for all of them. But for each state I need the default drop down item to be correspondent to the relevant to state. Can I achieve that through a custom field? Thank you
November 19, 2021 at 4:08 pm #35651Ernest Marcinko
KeymasterHi,
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; }January 10, 2022 at 1:37 pm #36220tharindu63
ParticipantIs there a way to delete or make private these tickets I have opened?
January 11, 2022 at 12:11 pm #36237Ernest Marcinko
KeymasterHi,
The tickets are public, but the replies can be made private. The private information on the ticket headers (like the URLs and login details) are not visible to other users.
I have removed every public URL from all of your tickets. -
AuthorPosts
- The topic ‘Default Dropdown item as a custom field’ is closed to new replies.