New Feature: Integration with Advanced Custom Fields Plugin
-
Thank you for your work on this excellent plugin.
I work on a web site that uses the Advanced Custom Fields plugin to embed images within a post with a different format than the standard WordPress featured image. The custom field option of your plugin was not retrieving the image URL when using the custom field name from ACF. Below is a code sample that detects if ACF is active, and the uses ACF’s function to retrieve the image URL.
Change line 508 of related-posts-thumbnails.php from…
$url = $basic_url = get_post_meta( $post->ID, get_option( 'relpoststh_customfield', $this->custom_field ), true );
to…
if ( function_exists( 'acf_shortcode' ) ) { $url = $basic_url = get_field( get_option( 'relpoststh_customfield', $this->custom_field ), $post->ID ); } else { $url = $basic_url = get_post_meta( $post->ID, get_option( 'relpoststh_customfield', $this->custom_field ), true ); }
The specified custom field in ACF needs to be set to return Image URL for this to work (default is Image Object). Since the above code is executed in a loop, it could probably be optimized by calling function_exists( ‘acf_shortcode’ ) and get_option( ‘relpoststh_customfield’, $this->custom_field ) before the loop.
- The topic ‘New Feature: Integration with Advanced Custom Fields Plugin’ is closed to new replies.