Support

Account

Home Forums General Issues Relationship field multiple: get position

Helping

Relationship field multiple: get position

  • Hello
    I use a relationship field multiple between multiple posts.
    In the field: i can reorder the field by drag and drop.

    To display the related posts i use:

    <?php foreach( $featured_posts as $post ): 
    	setup_postdata($post);
    	get_template_part( 'template-parts/content-archive');
    endforeach; 
    wp_reset_postdata();?> 

    Is it possible to retrieve the position number in the list (1rst, second, …) and display it?

    Thank’s for help

    Vince

  • You would need to add a counter and you would need to pass that counter to the template part. Passing arguments to the template part is a relatively new feature of get_template_part()

    
    <?php 
      $counter = 1;
      foreach ($featured_posts as $post) {
        setup_postdata($post);
        $args = array('counter' => $counter);
        get_template_part('template-parts/content-archive', NULL, $args);
        $counter++;
      }
      wp_reset_postdata();
    ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.