Support

Account

Home Forums General Issues Link field type get featured page image

Solving

Link field type get featured page image

  • Hi there. Is it possible to get not only Page title and page link when using Link field type?
    I mean it would be great to get Feature image, Page title, Page link.

    Tried to edit class-acf-field-link.php file and Add Thumbnail

    function get_link( $value = '' ) {
    		
    		// vars
    		$link = array(
    			'title'		=> '',
    			'thumbnail'	=> '',
    			'url'		=> '',
    			'target'	=> ''
    		);
    		
    		
    		// array (ACF 5.6.0)
    		if( is_array($value) ) {
    			
    			$link = array_merge($link, $value);
    		
    		// post id (ACF < 5.6.0)
    		} elseif( is_numeric($value) ) {
    			
    			$link['title'] = get_the_title( $value );
    			$link['thumbnail'] = get_the_post_thumbnail_url( $value );
    			$link['url'] = get_permalink( $value );
    		
    		// string (ACF < 5.6.0)
    		} elseif( is_string($value) ) {
    			
    			$link['url'] = $value;
    			$link['thumbnail'] = $value;
    			
    		}

    But it doesnt work 🙁 Please help

  • The values in a Link you set when you create the link and there is no way to get the featured image.

    If you are trying to get that information you should look into using Relationship
    https://www.advancedcustomfields.com/resources/relationship/

  • Or a post object field

    The only advantage of a link field is that you can link to other things besides posts, like archives and such.

    If you really need to use a link field you could also try https://developer.wordpress.org/reference/functions/url_to_postid/

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

You must be logged in to reply to this topic.