0
<?php include_once('header.php');?>
<?php the_title();?>
<?php
    $featured_posts = get_field('stars_relationship');
    if( $featured_posts ): ?>
    <ul>
    <?php foreach( $featured_posts as $post ): 

        // Setup this post for WP functions (variable must be named $post).
        setup_postdata($post); ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <span>A custom field from this post: <?php the_field( 'date_released'); ?></span>
            <?php
            $date = get_field("date_released");

            // assuming your return format is "Ymd"
            $dateTime = DateTime::createFromFormat("Y", $date);
            
            if ( is_object($dateTime) ) {
              $month = $dateTime->format('F');
              $year = $dateTime->format('Y');
              //...
            }
            ?>
         
        </li>
    <?php endforeach; ?>
    </ul>
    <?php 
    // Reset the global post object so that the rest of the page works correctly.
    wp_reset_postdata(); ?>
<?php endif; ?>

<?php include_once('footer.php');?>

Hi, Im working with the project. Im trying to arrange or achieve the format of related data by Year with ACF relationship field with datepicker without arranging directly inside on ACF plugins.

this is the sample output.

Actor name

Movie 18 - 2023
Movie 17 - 2022
Movie 16 - 2019
Movie 10- 1998
Movie 9 - 1950

I want to arrange by Year,

what im getting right now is, when i put the link on relationship field im getting the latest link on it. which is i dont want.

where is the best way to do it? Post Object or Relationship Field???

  • You will need to do a date sort in your foreach. https://stackoverflow.com/q/48619514/3739498 There is a similar issue here. The OP put his fix in a comment. – Aibrean Nov 27 '22 at 17:05
  • Its hard to achieve.. –  Nov 27 '22 at 17:21

0 Answers0