Support

Account

Home Forums General Issues Show post meta from a post object in a repeater

Solved

Show post meta from a post object in a repeater

  • Hi All,

    We are working on a fight event page with multiple fighters for the line up.
    We are using a repeater field with post object. We want to show the fighters on the page with some value out of the custom fields of these fighters. So that we only have to choose the fighters and not manually set all the fighter info multiple times on different pages. With over more than 200 fighters and multiple events this otherwise will be alot of work haha.

    The problem is that everytime we use the $figter_first_name = get_post_meta( $output, ‘name’, true); to show a value of a custom field from that fighter it stops the loop.

    This is the code we are using:
    function event_repeater( ){
    global $post;

    if( have_rows(‘event_fights’)): // check for repeater fields ?>

    <div class=”a-container”>

    <?php while ( have_rows(‘event_fights’)) : the_row(); // loop through the repeater fields

    // set up post object
    $post_object = get_sub_field(‘fight1’);
    if( $post_object ) :
    $post = $post_object;
    setup_postdata($post);
    ?>

    <article class=”your-post”>
    <?php // whatever post stuff you want goes here ?>

    </article>

    <?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly

    endif;
    $post_object = get_sub_field(‘fight2’);

    if( $post_object ) :
    $post = $post_object;
    setup_postdata($post);
    $figter_first_name = get_post_meta( $post_object, ‘name’, true);
    ?>

    <article class=”your-post”>
    <?php
    echo $post_object; //this is the ID
    echo $figter_first_name;
    ?>

    </article>

    <?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>

    <?php endif; ?>

    <?php endwhile; ?>

    </div>
    <!– End Repeater –>
    <?php endif;
    }

    add_shortcode( ‘event-repeat’, ‘event_repeater’ );

    Thanks in advanced!

  • Nevermind my co worker is a dickhead and told me he filled in the custom field but he didn’t hahah

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

You must be logged in to reply to this topic.