• Hi everyone. I have an event site and have created pages for artists.
    I would like events containing the artist’s name to be shown on the artist pages, taking the name directly from the title.
    For example, if I am on the artist’s page simply entitled Gigi D’Agostino, I would like all events containing the word Gigi D’Agostino to be searched for and shown accordingly.
    To do this I extrapolated the original code of the “search” shortcode from events manager.
    I renamed it “newsearch” and for now it works exactly like “search” i.e. using the string
    [event_list newsearch=”The post title should be used here”]
    Please, could someone tell me how to change the code to automatically search from the post title?
    The code I changed only for newsearch (instead of search) is the following:

    add_filter('em_events_get_default_search', 'my_custom_em_get_default_search', 1, 2);
    function my_custom_em_get_default_search($args, $array){
        $args['newsearch'] = false; // Imposta 'newsearch' come valore accettabile, sebbene sia impostato su false per impostazione predefinita
        if (!empty($array['newsearch'])) {
            $args['newsearch'] = $array['newsearch'];
        }
        return $args;
    }
    
    add_filter('em_events_build_sql_conditions', 'my_em_styles_events_build_sql_conditions', 1, 2);
    
    function my_em_styles_events_build_sql_conditions($conditions, $args) {
        global $wpdb;
        if (!empty($args['newsearch'])) {
            if (get_option('dbem_locations_enabled')) {
                $like_search = array('event_name', EM_EVENTS_TABLE . '.post_content', 'location_name', 'location_address', 'location_town', 'location_postcode', 'location_state', 'location_country', 'location_region');
            } else {
                $like_search = array('event_name', EM_EVENTS_TABLE . '.post_content');
            }
            $like_search_string = '%' . $wpdb->esc_like($args['newsearch']) . '%';
            $like_search_strings = array();
            foreach ($like_search as $v) $like_search_strings[] = $like_search_string;
            $like_search_sql = "(" . implode(" LIKE %s OR ", $like_search) . "  LIKE %s)";
            $conditions['newsearch'] = $wpdb->prepare($like_search_sql, $like_search_strings);
        }
        return $conditions;
    }
    
  • The topic ‘Shortcode search automatically in Title’ is closed to new replies.