• I am using
    echo do_shortcode('[yasr_overall_rating size="medium"]');
    to show ratings in a single page, everything works fine.

    I also need to view the ratings in a googlemap popup (Pronamic plugin).
    I am able to output in the popup everything I need from the post except for the ratings.

    This is the code to customize the popup in my functions.php:

    function prefix_pgmm_item($itemContent) {
    	$itemContent = '';
    	$itemContent .= '	<a href="'. get_permalink() .'">';
    	$itemContent .= '		'. get_the_title();
    	$itemContent .= '	</a>';
    	$itemContent .= wpautop(get_post_meta(get_the_ID(), '_pronamic_google_maps_address', true));
    	global $post;
    	$MYvar = do_shortcode( '[yasr_overall_rating]' );
    	$itemContent .= $MYvar;
    
    	return $itemContent;
    }
    add_filter('pronamic_google_maps_mashup_item', 'prefix_pgmm_item');

    $MYvar doesn’t show anything.
    Any idea?

    https://www.ads-software.com/plugins/yet-another-stars-rating/

Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Contributor dudo

    (@dudo)

    Hi,

    if inside the function prefix_pgmm_item you insert

    echo do_shortcode( '[yasr_overall_rating]' );

    does the echo works?

    Thread Starter Troglos

    (@troglos)

    no, I’ve tried already. It gives me a
    Parse error: syntax error, unexpected 'echo' (T_ECHO)

    Plugin Contributor dudo

    (@dudo)

    It shouldn’t give a parse error: can you please paste how did you put it?

    Thread Starter Troglos

    (@troglos)

    like this
    $MYvar = echo do_shortcode( '[yasr_overall_rating]' );

    even with double quotes gives me error

    Plugin Contributor dudo

    (@dudo)

    Of course it return an error, you can’t put an echo inside a var.

    you should simply do

    echo do_shortcode( '[yasr_overall_rating]' );

    so we can test if it work inside that function (that is called from add_filter)

    Thread Starter Troglos

    (@troglos)

    ok, but as you can see from my first piece of code, I need all the values in the $itemContent variable, to be visible in the googlemap popup

    Plugin Contributor dudo

    (@dudo)

    I understood that, but can you please do as I said? So we can see if the do_shortcode works inside that function

    Thread Starter Troglos

    (@troglos)

    sure, now the full code is this:

    function prefix_pgmm_item($itemContent) {
    	$itemContent = '';
    	$itemContent .= '<strong><a href="'. get_permalink() .'" class="titolo">' . get_the_title().'</a></strong>';
    	$itemContent .= wpautop(get_post_meta(get_the_ID(), '_pronamic_google_maps_address', true));
    	$itemContent .= '<a href="'. get_permalink() .'" class="moreinfo">Maggiori informazioni <span>&raquo;</span></a>';
    	echo do_shortcode( '[yasr_overall_rating]' );
    
    	return $itemContent;
    }
    add_filter('pronamic_google_maps_mashup_item', 'prefix_pgmm_item');

    no error, but no rating either

    Plugin Contributor dudo

    (@dudo)

    Ok, now we’re sure that we can’t use do_shortcode there.

    Can you please try this code

    function prefix_pgmm_item($itemContent) {
    	$itemContent = '';
    	$itemContent .= '<strong><a href="'. get_permalink() .'" class="titolo">' . get_the_title().'</a></strong>';
    	$itemContent .= wpautop(get_post_meta(get_the_ID(), '_pronamic_google_maps_address', true));
    	$itemContent .= '<a href="'. get_permalink() .'" class="moreinfo">Maggiori informazioni <span>?</span></a>';
    
            $MYvar = shortcode_overall_rating_callback();
    
            $itemContent .= $MYvar;
    
    	return $itemContent;
    }
    add_filter('pronamic_google_maps_mashup_item', 'prefix_pgmm_item');
    Thread Starter Troglos

    (@troglos)

    Now I get this error 4 times:

    Warning: Missing argument 1 for shortcode_overall_rating_callback()

    PS
    grazie per la pazienza ??

    Plugin Contributor dudo

    (@dudo)

    Yeah you’re right, try this

    function prefix_pgmm_item($itemContent) {
    	$itemContent = '';
    	$itemContent .= '<strong><a href="'. get_permalink() .'" class="titolo">' . get_the_title().'</a></strong>';
    	$itemContent .= wpautop(get_post_meta(get_the_ID(), '_pronamic_google_maps_address', true));
    	$itemContent .= '<a href="'. get_permalink() .'" class="moreinfo">Maggiori informazioni <span>?</span></a>';
    
            $atts = "medium";
    
            $MYvar = shortcode_overall_rating_callback($atts);
    
            $itemContent .= $MYvar;
    
    	return $itemContent;
    }
    add_filter('pronamic_google_maps_mashup_item', 'prefix_pgmm_item');
    Thread Starter Troglos

    (@troglos)

    no errors, but no stars yet

    Plugin Contributor dudo

    (@dudo)

    What if you try to insert a lower priority? (fore example)

    add_filter('pronamic_google_maps_mashup_item', 'prefix_pgmm_item', 200);

    Thread Starter Troglos

    (@troglos)

    Not working.

    Plugin Contributor dudo

    (@dudo)

    write me an email on d . curvino AT tiscali . it

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Shortcode in functions.php’ is closed to new replies.