• Resolved Tiago ADPS

    (@tiago-adps)


    Hi guys,

    I copied events-search.php to my child theme folder and edited it to show only the select box option.

    Since it’s the only search option I need, is it possible to submit the search form when I make a selection?

    Functionally something like this:
    ‘<select onchange=”this.form.submit()”>

    </select>’

    I tried to edit categories.php with no success so far.

    Thanks

    https://wordpress.org/plugins/events-manager/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Can you post a link?

    Thread Starter Tiago ADPS

    (@tiago-adps)

    Hi,

    Here’s the link: http://buranstudio.com/projects/mb/web15/ (top green box)

    Maybe there’s a way to loop through the category names (only names without formatting)? That way maybe I could wrap my code around it.

    Thanks

    If you’re not actually allowing a search (only sending users to the category page they selected), this is probably an easier solution:

    https://codex.wordpress.org/Function_Reference/wp_dropdown_categories#Dropdown_without_a_Submit_Button_using_JavaScript

    You would just need to change taxonomy to event_categories.

    Thread Starter Tiago ADPS

    (@tiago-adps)

    Thanks a lot for the answer! It ended up being more complicated than it seemed though.

    Those wp_dropdown_categories snippets were creating urls based on the IDs of the event categories (e.g http://www.mysite.com/?event-categories=3) which don’t exist. Fortunately I also found this answer that complemented yours.

    In case someone stumbles upon this, here’s what worked for my drop down events category menu that submits on select.

    <?php
    function replace_id_for_slug($option){
    	$categories = get_categories("taxonomy=event-categories&hide_empty=0");
    	preg_match('/value="(\d*)"/', $option[0], $matches);
    
    	$id = $matches[1];
    
    	$slug = "";
    
    	foreach($categories as $category){
    		if($category->cat_ID == $id){
    			$slug = $category->slug;
    		}
    	}
    
    	return preg_replace("/value=\"(\d*)\"/", "value=\"$slug\"", $option[0]);
    }
    
    $select = wp_dropdown_categories("taxonomy=event-categories&hierarchical=1&hide_empty=0&echo=0&show_option_none=Select category");
    $select = preg_replace_callback("#<option[^>]*>[^<]*</option>#", "replace_id_for_slug", $select);
    echo $select;
    ?>
    
    <script type="text/javascript"><!--
        var dropdown = document.getElementById("cat");
        function onCatChange() {
    		if ( dropdown.options[dropdown.selectedIndex].value != -1 ) {
    			location.href = "<?php echo get_option('home');?>?event-categories="+dropdown.options[dropdown.selectedIndex].value+"/";
    		}
        }
        dropdown.onchange = onCatChange;
    --></script>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Submit search form on select?’ is closed to new replies.