Title: Shortcode search automatically in Title
Last modified: May 30, 2024

---

# Shortcode search automatically in Title

 *  Resolved [akide](https://wordpress.org/support/users/akide/)
 * (@akide)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/shortcode-search-automatically-in-title/)
 * 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:
 *     ```wp-block-code
       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.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=1039078)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [akide](https://wordpress.org/support/users/akide/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/shortcode-search-automatically-in-title/)
 * Status: resolved