Help Desk

Creating events search form on homepage

  • Posts: 2 Topics: 2
    | Permalink

    Hi,

    I am currently struggling to implement a search form based off of Events Calender Pro and the filter bar add-on. We purchased the filter bar to make the following process easier but it has proven to be anything but easier.
    Essentially I need three fields (Categories, City and Province/State) with a submit button, naturally.

    I have managed to generate the submit button and a categories dropdown which works perfectly, however I can’t seem to generate the city and Province/States dropdowns. I know that they are reliant on venues and I have attempted multiple scenarios, but with no success. Could someone please assist with this and guide me in the right direction. Please see below the code that was implemented to get the categories dropdown to work. I have attempted to use the same structure of code used for categories and declare the information specific to city and states eg. ($searched_meta = ‘_VenueCity’; $relation_meta = ‘_EventVenueID’; $join_name = ‘city_filter’;), and call it into the input field to generate the necessary information but with no success. I think I need to communicate with base_meta.php in order to get the relevant information but I am not 100% sure. Any assistance will be greatly appreciated.

    <?php
    $taxonomy = TribeEvents::TAXONOMY;
    $orderby = ‘name’;
    $show_count = 1; // 1 for yes, 0 for no
    $pad_counts = 0; // 1 for yes, 0 for no
    $hierarchical = 1; // 1 for yes, 0 for no
    $title = ”;

    $args = array(
    ‘taxonomy’ => $taxonomy,
    ‘orderby’ => $orderby,
    ‘show_count’ => $show_count,
    ‘hierarchical’ => $hierarchical,
    ‘title_li’ => $title
    );
    ?>

    form code:

    <div class=”categories-container”>
    <?php $cats = get_categories($args); ?>
    <select id=”categories”>
    <option selected value=”” disabled>Event Categories</option>
    <?php foreach ($cats as $cat) : ?>
    <option value=”<?php echo get_term_link($cat, $cat->taxonomy) ?>”><?php echo $cat->name ?></option>
    <?php endforeach; ?>
    </select>
    </div>

    script:

    <script>
    jQuery(document).ready(function()
    {
    jQuery(‘#tribe-bar-form’).submit(function()
    {
    window.location = jQuery(‘#categories’).val();
    return false;
    });
    });
    </script>

    Thanks in advance.

    Kind Regards

    Posts: 2500
    | Permalink

    Hi there,

    Thanks for getting in touch with us!

    This essentially looks like a custom development task and so is outside of our stated scope of support.

    With that being said, we’d love to help point you in the right direction.

    We do need to prioritize support requests from other customers at this time but I’ll certainly flag this with the team and – although we can’t make any promises – if we have time and space to come back and help, we’ll be happy to do so.  Please let us know if you’d like to go this route so that you can be added to this queue.

    In the meantime, if there is any more information you can share (including mock-ups) that will help us to better understand what you are seeking please do feel free to add them to this ticket.

    If you urgently need help with this, however, you may instead wish to consider working with a suitably skilled developer or designer who can offer the additional level of support you require.

    Thanks and cheers,
    Brendan

    Posts: 2 Topics: 2
    | Permalink
    This reply has been marked as private.
    Posts: 2500
    | Permalink
    This reply has been marked as private.
    Posts: 2 Topics: 2
    | Permalink
    This reply has been marked as private.
    Posts: 18146 Topics: 17 Answers: 973
    | Permalink

    Sorry for the delay, Daniel.

    To fetch a list of cities you could use some code like this:

    function get_tec_venue_cities() {
    	global $wpdb;
    
    	$venues = (array) $wpdb->get_results( "
    		SELECT post_id, meta_value
    		FROM   $wpdb->postmeta
    		JOIN   $wpdb->posts ON post_id = ID
    		WHERE  meta_key = '_VenueCity'
    		AND    post_type = 'tribe_venue'
    	" );
    
    	$results = [];
    
    	foreach ( $venues as $venue ) {
    		$results[ $venue->post_id ] = $venue->meta_value;
    	}
    
    	return $results;
    }
    

    You could use this to populate a dropdown, something like this:

    echo '<select>';
    
    foreach ( get_tec_venue_cities() as $venue_id => $venue_name ) {
        echo '<option value="' . esc_attr( $venue_id ) . '">';
        echo esc_html( $venue_name );
        echo '</option>';
    }
    
    echo '';
    

    A similar approach could be used for states and so on. I do hope that helps, but at this point am going to close this topic: we’re experiencing exceptionally high demand for support right now and, unfortunately, will be unable to do any further work on this request.

    If you do need more support for out-of-scope requests like this one, though, please do consider reaching out to another dev resource as described here.

    Thanks!

    | Permalink