Display ACF (Advanced Custom Fields) Relational Link in WordPress Carousel


Wonder Carousel


I'm using Wonder Carousel Pro to create a Custom Post Type (ACF) carousel. The Custom Post Type contains a relational link type Advanced Custom Field "outside_link" that returns a url and the link text. I'd like to display that links in the carousel.

I added %outside_link% to the Field For Description input box, but in the published carousel, the link displayed as an object string instead of a web link:

a:3:{s:5:"title";s:11:"Wonder Plugin";s:3:"url";s:22:"https://www.wonderplugin.com";s:6:"target";s:0:"";}


Wonder Carousel has a filter wonderplugin_carousel_custom_post_field_content that you can use to modify the post data.

You can add the following PHP code to the end of the functions.php file of your WordPress theme. The code will convert the outside_link from an object to a string:

PLEASE NOTE, modifying functions.php and adding PHP code may break your WordPress. Please backup your WordPress before making the change.

function modify_outside_link( $postdata ) {
    if ( !empty($postdata['outside_link']) && is_array($postdata['outside_link']) )
      try {
        $outside_link = unserialize( $postdata['outside_link'][0] );
        if ( !empty($outside_link) )
          $postdata['outside_link'] = '<a href="' . $outside_link['url'] . '" target="' . $outside_link['target'] . '">' . $outside_link['title'] . '</a>';
      } catch (Exception $e) {}
    return $postdata;
add_filter( 'wonderplugin_carousel_custom_post_field_content', 'modify_outside_link' );