This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Default Dropdown item as a custom field

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Default Dropdown item as a custom field

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #35639
    tharindu63tharindu63
    Participant

    Hello
    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

    #35651
    Ernest MarcinkoErnest Marcinko
    Keymaster

    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;
    }
    #36220
    tharindu63tharindu63
    Participant

    Is there a way to delete or make private these tickets I have opened?

    #36237
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Default Dropdown item as a custom field’ is closed to new replies.