【问题标题】:Wordpress Custom Post Type with ACF Relationship Field with DatePickerWordpress Custom Post Type with ACF Relationship Field with DatePicker
【发布时间】:2022-12-01 19:00:40
【问题描述】:
<?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???

【问题讨论】:

标签: php wordpress advanced-custom-fields acfpro


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 2013-10-06
    • 2020-11-09
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多