• Resolved fauveauxm

    (@fauveauxm)


    Hello, I would like to adapt 2 functions in my event form please.

    1. I want to preselect the logged organizer per default in the select list.
    2. I want to only display the venues of one organizer in the select list.

    Could you help me please?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support wpemhelp

    (@wpemhelp)

    Hi,

    This would require some modifications to the coding on our side.

    Let me have a discussion with our technical team to see how we can help you.

    Thank You.

    Best Regards.

    Thread Starter fauveauxm

    (@fauveauxm)

    Hello,

    thanks ! ??

    Plugin Author Rita Kikani

    (@kikanirita)

    Hello @fauveauxm ,

    for the 1st point, you need to add below code in your theme functions.php file to get the current loggedin user organizer ids :

    function get_current_user_organizers(){
    
        $author_id = get_current_user_id();
    
        $organizer_ids = array();
    
        if ($author_id > 0) {
    
            $args = array(
    
                'author' => $author_id,
    
                'post_type' => 'event_organizer',
    
                'posts_per_page'    => -1,
    
            );
    
            $author_posts = new WP_Query( $args );
    
            if( $author_posts->have_posts() ) {
    
                while( $author_posts->have_posts() ) {
    
                    $author_posts->the_post();
    
                    array_push($organizer_ids, get_the_ID());
    
                }
    
                wp_reset_postdata();
    
            }
    
        }
    
        return $organizer_ids;
    
    }

    And one more thing you have to customize, you need to override below template file at your theme side :

    Need to copy the file from : wp-content\plugins\wp-event-manager\templates\form-fields\multiselect-field.php

    Need to paste that file here : wp-content\themes\YOUR_THEME_FOLDER\wp-event-manager\form-fields\multiselect-field.php

    In your multiselect-field.php file, you need to do customize code as per your requirements. For Example, you can write this code in that file to resolve your first issue :

    <?php wp_enqueue_script('wp-event-manager-multiselect');
    
    wp_register_script( 'chosen', EVENT_MANAGER_PLUGIN_URL . '/assets/js/jquery-chosen/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
    
    wp_register_script( 'wp-event-manager-multiselect', EVENT_MANAGER_PLUGIN_URL . '/assets/js/multiselect.min.js', array( 'jquery', 'chosen' ), EVENT_MANAGER_VERSION, true );
    
    wp_enqueue_style( 'chosen', EVENT_MANAGER_PLUGIN_URL . '/assets/css/chosen.css' );
    
    if(!isset($field['name']) && $key == 'event_organizer_ids'){
    
        //this will return all ids of organizers for current loggedin user
    
        $organizer_ids = get_current_user_organizers();
    
        if(!empty($organizer_ids)){
    
            $selected = $organizer_ids[0];
    
            $field['value'] =  $organizer_ids[0];
    
        }
    
    }
    
    if(!empty($field['value']) && is_array($field['value'])){
    
        $selected = 'selected="selected"';
    
    }else if($key == 'event_organizer_ids' && !empty($field['value'])){
    
        $selected = 'selected="selected"';
    
    }
    
    ?>
    
    <select multiple="multiple" name="<?php echo esc_attr(isset($field['name']) ? $field['name'] : $key); ?>[]" id="<?php echo esc_attr($key); ?>" class="event-manager-multiselect" data-no_results_text="<?php _e('No results match', 'wp-event-manager'); ?>" attribute="<?php echo esc_attr(isset($field['attribute']) ? $field['attribute'] : ''); ?>" data-multiple_text="<?php _e('Select Some Options', 'wp-event-manager'); ?>">
    
        <?php foreach ($field['options'] as $key => $value) : ?>
    
            <option value="<?php echo esc_attr($key); ?>" <?php echo $selected; ?>><?php echo esc_html($value); ?></option>
    
        <?php endforeach; ?>
    
    </select>
    
    <?php if (!empty($field['description'])) : ?>
    
        <small class="description">
    
            <?php printf ($field['description']); ?>
    
        </small>
    
    <?php endif; ?>

    The same way you can follow to solve your 2nd issue.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Select venue and organizer per default in form’ is closed to new replies.