Home Forums ACF PRO Query relationship field in repeater


Query relationship field in repeater

  • Hello,

    Ive the custom post types:

    – Winevideos
    – Wines

    In each “Winevideo” post is an embedded youtube video in which several “Wines”are discussed, so this post type has a repeater field with relational field (for the wine) and an textfield for the timecode.

    On the Wine detail page there is a back link to the Winevideo post in which the wine has been discussed. I found an example for this query in this forum – however I have massive problems to query the timecode for the wine …how is this possible?


  • <?php
     * The Template for displaying all single posts
     * @package WordPress
     * @subpackage Twenty_Fourteen
     * @since Twenty Fourteen 1.0
    get_header(); ?>
    // custom filter to replace '=' with 'LIKE'
    function my_posts_where( $where )
    	$where = str_replace("meta_key = 'list-wines_%_item-wine'", "meta_key LIKE 'list-wines_%_item-wine'", $where);
    	return $where;
    add_filter('posts_where', 'my_posts_where');
    // args
    $args = array(
    	'post_type'	=> 'post',
    	'meta_query' => array(
    			'key' => 'list-wines_%_item-wine',
    			'value' => '"' . get_the_ID() . '"',
    			'compare' => 'LIKE'
    // get results
    $the_query = new WP_Query( $args );
    // The Loop
    if( $the_query->have_posts() ): ?>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post();
        $parent_id = get_the_ID();
    			<a href="<?php the_permalink(); ?>"><?php the_ID(); the_title(); ?></a>
    	<?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>

    I got the snippet from the forums…I need to get the time code for the item-wine to, not just the title. Could anyone give me a hint, please

  • No input on this one?

  • Hi @fountain

    Please find the following tutorial for querying sub field values:

    If the code ends up becoming a performance issue, or is simply too complicated and difficult to understand, please consider creating a new post type called ‘wine-video’. Each wine-video post could contain the video, wines, etc and would allow for much more simple and basic WP querying!


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

The topic ‘Query relationship field in repeater’ is closed to new replies.