Support

Account

Home Forums ACF PRO Query relationship field in repeater

Solving

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?

    best
    p.

  • <?php
    /**
     * The Template for displaying all single posts
     *
     * @package WordPress
     * @subpackage Twenty_Fourteen
     * @since Twenty Fourteen 1.0
     */
    
    get_header(); ?>
    
    	<?php 
     
    // 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(
    		array(
    			'key' => 'list-wines_%_item-wine',
    			'value' => '"' . get_the_ID() . '"',
    			'compare' => 'LIKE'
    		)
    	)
    );
     
    // get results
    $the_query = new WP_Query( $args );
     
    // The Loop
    ?>
    <?php 
    
    if( $the_query->have_posts() ): ?>
    
     
    	<ul>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post();
    
        $parent_id = get_the_ID();
        
    
      
        
    
    	 ?>
    		<li>
    			<a href="<?php the_permalink(); ?>"><?php the_ID(); the_title(); ?></a>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    <?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:
    http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-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!

    Cheers
    E

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

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