Title: Search inside shortcode
Last modified: September 14, 2022

---

# Search inside shortcode

 *  Resolved [oneguy](https://wordpress.org/support/users/oneguy/)
 * (@oneguy)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/)
 * Hi There
    I tried all the option including expand shortcode etc but the search
   doesn’t find anything inside this shortcode. Any help will be greatly appreciated.
 * `function get_user_recognition() {
 *  ?><span>מפרגים ל:</span> <?php
 *  $values = get_field(‘users-selected’);
 * foreach($values as $value):
 * $result = $value[‘display_name’] . ‘ | ‘;
 * endforeach;
 * return $result;
 * }
    add_shortcode( ‘recognition-users’, ‘get_user_recognition’ );’
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsearch-inside-shortcode%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16010190)
 * This looks like a problem:
 * `?><span>מפרגים ל:</span> <?php`
 * Shortcode functions should never output or echo anything directly; all output
   should be returned as the function return value. Try moving the `<span>` to the`
   $result` variable. That may help.
 * Also, make sure the shortcode is defined in the Relevanssi indexing content and
   not only in the front end.
 *  Thread Starter [oneguy](https://wordpress.org/support/users/oneguy/)
 * (@oneguy)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16012386)
 * Thank you so much for your reply 🙂
    I deleted the span line so now there is 
   only $results.
 * “Also, make sure the shortcode is defined in the Relevanssi indexing content 
   and not only in the front end.”
 * This I did not understand.
    I checked – “Expand shortcodes when indexing”; and
   hit the index again. Must say this is a custom post type that it is indexed as
   well.
 * Anything else I am missing?
 *     ```
       // Add Shortcode
       function get_user_recognition() {
   
         $values = get_field('users-selected');
   
       foreach($values as $value):
   
       $result =  $value['display_name'] . ' | ';
   
       $result .= 'סולומון';
       endforeach;
   
       return $result;
   
       }
       add_shortcode( 'recognition-users', 'get_user_recognition' );
       ```
   
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16012732)
 * I mean that sometimes shortcode functions are only defined in the front-end context.
   The function doesn’t exist in the WP admin. If that’s the case, the Relevanssi
   debugger (Settings > Relevanssi > Debugging) should index the shortcode name,
   not the contents. If you look at a post with this shortcode with the debugger,
   is the shortcode content missing and do the words “recognition” and “users” appear
   in the post content?
 *  Thread Starter [oneguy](https://wordpress.org/support/users/oneguy/)
 * (@oneguy)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16022044)
 * Thank you so much for your reply!
    No… I get only this –
 *     ```
       The title
       דשששששש חדש פרגון
   
       The content
       בקצרה
   
       Authors
       גיא
   
       Custom fields
       290
       ```
   
 * and in the “How does the post look like in the database?
    ”
 * I get only the content.
 * Any advice will be greatly appreciated 🙂
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16022091)
 * Is the shortcode in the post content or somewhere else in the post? Like a custom
   field?
 *  Thread Starter [oneguy](https://wordpress.org/support/users/oneguy/)
 * (@oneguy)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16022398)
 * The shortcode is outside the content – It takes the acf user field and displays
   it’s user diplay name.
 * [https://buddy.digitalguru.co.il/love/%D7%A4%D7%A8%D7%92%D7%95%D7%9F-%D7%97%D7%93%D7%A9-%D7%97%D7%93%D7%A9-%D7%97%D7%93%D7%A9-%D7%93%D7%A9%D7%A9%D7%A9%D7%A9%D7%A9%D7%A9](https://buddy.digitalguru.co.il/love/%D7%A4%D7%A8%D7%92%D7%95%D7%9F-%D7%97%D7%93%D7%A9-%D7%97%D7%93%D7%A9-%D7%97%D7%93%D7%A9-%D7%93%D7%A9%D7%A9%D7%A9%D7%A9%D7%A9%D7%A9)
 *  Plugin Author [Mikko Saari](https://wordpress.org/support/users/msaari/)
 * (@msaari)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16022502)
 * Relevanssi only sees the post. If the shortcode is in the template, Relevanssi
   doesn’t see it at all.
 * If you want to add extra content to the posts, you can use the [`relevanssi_content_to_index`](https://www.relevanssi.com/user-manual/filter-hooks/relevanssi_content_to_index/)
   filter hook to add the shortcode function value to the post.
 *  Thread Starter [oneguy](https://wordpress.org/support/users/oneguy/)
 * (@oneguy)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16025740)
 * Thank you so much for your support!!!!
 * I finaly managed 🙂
 *     ```
       add_filter( 'relevanssi_content_to_index', 'rlv_add_extra_content', 10, 2 );
       function rlv_add_extra_content( $content, $post ) {
           global $wpdb;
   
             $values = get_field('users-selected');
   
       foreach($values as $value):
   
           $content .= $value['display_name'] ;
   
           endforeach;
   
   
   
           return $content;
       }
       ```
   

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Search inside shortcode’ is closed to new replies.

 * ![](https://ps.w.org/relevanssi/assets/icon-256x256.png?rev=3529670)
 * [Relevanssi - A Better Search](https://wordpress.org/plugins/relevanssi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/relevanssi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/relevanssi/)
 * [Active Topics](https://wordpress.org/support/plugin/relevanssi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/relevanssi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/relevanssi/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 8 replies
 * 2 participants
 * Last reply from: [oneguy](https://wordpress.org/support/users/oneguy/)
 * Last activity: [3 years, 8 months ago](https://wordpress.org/support/topic/search-inside-shortcode/#post-16025740)
 * Status: resolved