Support » Plugin: Relevanssi - A Better Search » Search inside shortcode

  • Resolved oneguy

    (@oneguy)


    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 to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mikko Saari

    (@msaari)

    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

    (@oneguy)

    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

    (@msaari)

    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

    (@oneguy)

    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

    (@msaari)

    Is the shortcode in the post content or somewhere else in the post? Like a custom field?

    Thread Starter oneguy

    (@oneguy)

    Plugin Author Mikko Saari

    (@msaari)

    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 filter hook to add the shortcode function value to the post.

    Thread Starter oneguy

    (@oneguy)

    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)
  • You must be logged in to reply to this topic.