• Resolved Jacob Wonder

    (@jacobwonder)


    Instead of just looking at the Gutenberg for the YouTube link, could it grab it from and ACF video field?

    Ideally I would like to have a client use only ACF.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    You should be able to use this filter to change the blob of content searched through, including possible sources like meta data.

    https://github.com/WebDevStudios/Automatic-Featured-Images-from-Videos/blob/master/automatic-featured-images-from-videos.php#L101-L113

    Including some of the code immediately above it to illustrate part of what we’re doing with the spot and how we set what content to initially search through.

    Thread Starter Jacob Wonder

    (@jacobwonder)

    Thank you very much for the direction! Perfect.

    I’ll have a fun time breaking that down and figuring it out with ACF!

    Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    Admittedly it’s a little bit “global” and stomping in this version, but if you’re only wanting to search by a given ACF field:

    function wds_featured_images_support_acf( $content, $post_id ) {
    	$acf = get_field( 'my-field', $post_id );
    
    	if ( ! empty( $acf ) ) {
    		return $acf;
    	}
    
    	return $content;
    }
    add_filter( 'wds_featured_images_from_video_filter_content', 'wds_featured_images_support_acf' );
    

    However, since we can concatenate strings, you could also do return $content .= $acf and fetch as many fields as you may need. It’d give you the post content and the fields to search through.

    This is exactly what I’m looking for! I have added this into my functions.php file and updated the ACF field I want, but whenever I try to save any type of content now, I get a “critical error” message. Should I be placing this somewhere else?

    function wds_featured_images_support_acf( $content, $post_id ) {
    $acf = get_field( 'video_url', $post_id );
    if ( ! empty( $acf ) ) {
    return $acf;
    }
    return $content;
    }
    add_filter( 'wds_featured_images_from_video_filter_content', 'wds_featured_images_support_acf' );

    Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

    I was going to request that you check on the error itself so we could confirm what’s going on.

    However, upon some quick review, and due to no followup from the original thread starter, I never noticed my error from almost 2 months ago.

    Need to change this:

    add_filter( 'wds_featured_images_from_video_filter_content', 'wds_featured_images_support_acf' );
    

    to this:

    add_filter( 'wds_featured_images_from_video_filter_content', 'wds_featured_images_support_acf', 10, 2 );
    

    Dude, that is the fastest reply ever — even compared against online chats!

    Works perfectly now! Thanks.

    Plugin Support Michael Beckwith

    (@tw2113)

    The BenchPresser

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘ACF Integration’ is closed to new replies.