Support

Account

Home Forums General Issues Calling shortcode within $retour

Solved

Calling shortcode within $retour

  • Hi Everyone,

    I hope someone can help me. I’m trying to call a Custom Field into a fuction using the below process. But its not calling the image in.

    Can anyone point me in the direction / show me what i’m doing wrong:

    add_filter('widget_text', 'do_shortcode');
    
    function sc_liste1($atts, $content = null) {
            global $post;
            $myposts = get_posts('post_type=map-location&numberposts=10&order=ASC&location-tag=graduates');
    
            foreach($myposts as $post) :
                    setup_postdata($post);
    		$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
                 $retour.='<a href="'.get_permalink().'" class="graduatelinkbutton"><img src="'.the_field('featured_image_for_mobile').'"><span class="gradcontent"><strong>'.the_title("","",false).'</strong><br>'.get_the_excerpt().'</span></a>';
            endforeach;
    
            return $retour;
    }
    add_shortcode("graduateslist", "sc_liste1");

    I’m sure that the problem is in the part with ‘the_field(‘featured_image_for_mobile’)’

    I have tried to make it only say featured_image_for_mobile, but it just displays a blank square.

    Thanks in advance

    Chris

  • Where you have the_field('featured_image_for_mobile') try changing it to the_field('featured_image_for_mobile', $post->ID).

  • Unfortunately that didn’t work. All it ends up doing is displaying the full URL of the image instead of the image itself.

    I decided not to worry about making it a shortcode. I have instead just made a template using the <?php method instead which seems to work perfectly 🙂

    Thanks for your help though Hube2 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.