WordPress.org

Ready to get started?Download WordPress

Forums

Related Posts by Zemanta
[resolved] Custom posts (ACF) - Can't display thumbnails - getting ID instead of url (5 posts)

  1. letterafterz
    Member
    Posted 3 months ago #

    Hey guys,

    Great plugin, but I'm having an issue. Using a custom field as set using the ACF plugin - http://www.advancedcustomfields.com/

    It's pulling images up as their image ID instead of URLs and I can't seem to fix it short of hacking the plugin code (not ideal).

    Is there an option to deal with custom fields which are storing the image ID? (I assume that's the issue).

    Output is like this:

    <img src="726" alt="blah blah" width="150" height="150">

    https://wordpress.org/plugins/related-posts-by-zemanta/

  2. letterafterz
    Member
    Posted 3 months ago #

    My temporary workaround is to edit thumbnailer.php in the theme:

    LINE 201

    /**
     * Get thumbnails when post is displayed
     */
    
    function wp_rp_get_img_tag($src, $alt, $size=null) {
    	if (!$size || !is_array($size)) {
    		$size = array(WP_RP_THUMBNAILS_WIDTH, WP_RP_THUMBNAILS_HEIGHT);
    	}
    	$size_attr = ($size[0] ? ('width="' . $size[0] . '" ') : '');
    	if ($size[1]) {
    		$size_attr .= 'height="' . $size[1] . '" ';
    	}
    
    	/* MY HACK */
    		//get image from ID if it's a number
    		if (is_numeric($src)):
    			$src = wp_get_attachment_image_src( (esc_attr($src)), 'thumbnail' );
    		else:
    			$src[0] = $src;
    		endif;
    
    		return '<img src="'. $src[0] . '" alt="' . esc_attr($alt) . '" '.$size_attr.'/>';
    	/* END HACK */
    }
  3. silvoslaf
    Member
    Plugin Author

    Posted 3 months ago #

    Hey, thanks for reaching out & I would love to help you out, but in order to do so we would need a bit more information, if possible.

    Is there a chance you could send us the link to the blog in question, so that we could have a closer look at those images and their ID's?

    Let us know, we're eager to help you out! Take care & I'm looking forward to your reply!

    Best,
    Silvo

  4. letterafterz
    Member
    Posted 1 month ago #

    I've resolved the issue now by using image objects in acf instead of image IDs.

  5. silvoslaf
    Member
    Plugin Author

    Posted 1 month ago #

    Hey, that's great news, really glad you found your way around the problem, to honest!

    But please do let me know if something similar happens again or if there's anything else that I can help you with, since I'll gladly do it!

    Take care & enjoy your weekend ahead!

    Best,
    Silvo

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.