Home Forums General Issues Display field from subpage on parent, via WP_Query


Display field from subpage on parent, via WP_Query

  • Hi. I’m currently doing a website for an artist, where their projects are all subpages of a parent page. Each project has a video. The Vimeo ID of the video is an ACF text field for each subpage, called vimeo_link_id.

    I want to make a parent page that lists all the projects, and also includes the videos.

    At the moment, I’m displaying the excerpts of the content from each subpage via a WP_Query loop. This loop is in functions.php, and is integrated into the parent page via a shortcode.

    I can’t figure out how to get the Vimeo ID to display in this loop.

    Here is my current code. Can anyone tell me how to do this?


     * list child pages - Work page list
    function list_works() {
        global $post;
        //query subpages
        $args = array(
            'post_parent' => $post->ID,
            'post_type' => 'page',
            'posts_per_page' => 999
        $subpages = new WP_query($args);
        // create output
        if ($subpages->have_posts()) :
            $output = '<!-- begin child pages -->';
            while ($subpages->have_posts()) : $subpages->the_post();
                $output .= '<div class="marquee"><div class="content">
                			<h2 class="sub">' . get_the_title() . ' <span>' . get_the_date('Y') . '</span></h2>
                            '. get_the_post_thumbnail( $page->ID, 'thumbnail' ) .'
                           vimeo_link_id here please!!
                            <p>'.get_the_excerpt().' | <a href="'.get_permalink().'">Full details »</a></p>
                            </div> <!-- .content --> </div> <!-- .marquee -->';
            $output .= '<!-- end child pages -->';
        else :
            $output = '<p>No subpages found.</p>';
        // reset the query
        // return something
        return $output;
    add_shortcode('list_works', 'list_works');
  • Because you are using the global $post and and the loop you should just need to get the field or show the field with get_field(‘vimeo_link_id’) or the_field(‘vimeo_link_id’). I can’t give you any help on what you actually need to add for HTML to show the video, I would assume some type of iframe.

  • Thanks. I rewrote it slightly in light of what you said, and I have it working now.

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

You must be logged in to reply to this topic.