Support

Account

Home Forums ACF PRO oEmbed field for first post of query

Solved

oEmbed field for first post of query

  • I’m trying to integrate an oEmbed field into someone else’s WordPress template. Here’s what I have to work with.

                if( 
                    is_array( ( $fp = get_posts( array(
                        'post_type' => 'featured_project',
                        'post_status' => 'publish',
                        'numberposts' => 1
                    ) ) ) )
                    AND count( $fp ) 
                ):
    ?>
                    <section id="section-third">
                        <div class="container">
                            <div class="row">
                                <div class="col-md-12">
                                    <h1 class="section-heading">Featured Project</h1>
                                </div>
                                <div class="col-md-5">
    
                                    <?php $video = $fp[0]->youtube_video; ?>
    
                                    <?php if($video) : ?>
                                        <?php echo $fp[0]->youtube_video; ?>
                                    <?php else: ?>
                                        <?php echo get_the_post_thumbnail( $fp[0]->ID, 'full', array( 'class' => 'img-responsive' ) ); ?>
                                    <?php endif; ?>

    Everything after col-md-5 is mine. This just outputting a YouTube URL, not the video itself. What needs to change?

  • Hi @joshkern

    I’m afraid I can’t see the usage of ACF there. If you want to show an oEmbed field, kindly check this page: https://www.advancedcustomfields.com/resources/oembed/.

    In your case, you should pass the ID of the post like this:

    the_field('oembed_field_name', $fp[0]->ID);

    I hope this helps 🙂

  • This is exactly what I needed. A lot of this is new to me, so I really appreciate the help.

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

The topic ‘oEmbed field for first post of query’ is closed to new replies.