Support

Account

Home Forums Add-ons Repeater Field How to get a value from another repeater field? Reply To: How to get a value from another repeater field?

  • Hi @elliot

    sorry for that. so i’m going to explain it to you 🙂

    This is the code i took from your documentation (example 4):

    <?php 
     
    // args
    $args = array(
    	'numberposts' => -1,
    	'post_type' => 'event',
    	'meta_query' => array(
    		'relation' => 'OR',
    		array(
    			'key' => 'location',
    			'value' => '%Melbourne%',
    			'compare' => 'LIKE'
    		),
    		array(
    			'key' => 'location',
    			'value' => '%Sydney%',
    			'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(); ?>
    <li>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>
    	</ul>
    <?php endif; ?>
     
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>

    And the following code is an extract of my entire liveticker code (http://derschlag-handball.de/liveticker). My liveticker works perfect so far, but it takes too much time to fill in all the fields when e.g. somebody makes a goal, etc.

    So what I did was to create another repeater field for each team, where I can write in all players with their numbers. When the match is running I only have to type in the number of the player and in my liveticker the name of the player will be picked from the new created repeater field.

    And there’s my problem. The liveticker repeater field works perfectly (where I always have to type in the players name and number). I also created a second (and third) repeater field for the team-list (number and name of each player). But my code with the modified query of your example (above) does not work:

    <?php
    $number = get_sub_field(‘liveticker_nummer’);
    $name = array(
    ‘numberposts’ => 1,
    ‘post_type’ => ‘liveticker’,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘nummer_heim’,
    ‘value’ => $number,
    )
    )
    );
    $name_query = new WP_Query( $name );?>
    
    …
    
    <?php if(get_sub_field(‘ereignis’) == “Tor”) : ?>
    durch <?php if( $name_query->have_posts() ) : while ( $name_query->have_posts() ) : $name_query->the_post(); ?>
    <?php the_field(‘name_heim’);?><?php endwhile; endif; ?> (<?php the_sub_field(‘liveticker_nummer’);?>)</p>
    
    …

    get_sub_field(‘liveticker_nummer’) = get’s the number of the player I tiped in the liveticker repeater field (for each event, like e.g goal)

    ‘nummer_heim’ = the field of my team-list, where the number of the player is listed

    ‘value’ => $number = my goal is that the code uses the number in the liveticker repeater field to query the row of the team-list where also his name is located

    the_field(‘name_heim’) = the name which belongs to $number in the team-list

    I hope you understand what I mean and can help me with that! thanks 🙂