$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>advanced custom fields - ACF Pro Date Picker not coming through on Loop|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

advanced custom fields - ACF Pro Date Picker not coming through on Loop

matteradmin9PV0评论

I have a CPT with a set of fields set by ACF Pro - one of which is a date picker. I created a shortcode that can display these CPT's to a page and everything works except for the date. The date that shows through is the date of the first post created (it sets that date for all instances of the post-type instead of pulling through the date set for each individual entry)

I am trying to create a date object so that I can render the day and month above the year for stylistic purposes - I know I can just use the_field('date') otherwise but then I can't split the format up.

Can anyone see any issues or suggest how I can get this to show through?

//EVENTS SHORTCODE

add_shortcode('events', 'create_events_shortcode');
function create_events_shortcode ($atts){
    //merge the passed attributes with defaults
    extract(
        shortcode_atts(
            array(
                'post_type'         => 'event',
                'post_status'       => 'publish',
                'posts_per_page'    => 12,
            ),
            $atts
        )
    );

    // Custom Excerpt function for Advanced Custom Fields
    function custom_field_excerpt() {
        global $post;
        $text = get_field('event_description'); //Replace 'your_field_name'
        if ( '' != $text ) {
            $text = strip_shortcodes( $text );
            $text = apply_filters('the_content', $text);
            $text = str_replace(']]>', ']]>', $text);
            $excerpt_length = 20; // 20 words
            $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
            $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
        }
        return apply_filters('the_excerpt', $text);

    }

    // get raw date
    $date = get_field('date');


    // make date object
    $date = new Datetime($date);
    //now create a seprate agruments array for wp_query using the values from above(extracted variables)
    $args = array(
        'post_type'         => $post_type,
        'post_status'       => $post_status,
        'posts_per_page'    => $posts_per_page
    );

    ob_start();

    $my_query = new WP_Query( $args );
    if( $my_query->have_posts() ) {
        ?>
        <div id="nbf-event-list">
            <?php
            while ($my_query->have_posts()) : $my_query->the_post(); ?>

            <div class="individual-event"> 
                <div class="event-intro">
                    <div class="date-format">
                        <span class="date-details"><?php echo $date->format('jS F'); ?></span>
                        <span class="date-text"><?php echo $date->format('Y'); ?></span>
                    </div>  
                    <a href=" <?php the_permalink(); ?> "><h3 class="event-title"><?php the_title(); ?></h3></a>
                </div>

                <div class="main-event-box">                
                <div class="event-meta">
                    <h5>EVENT DETAILS</h5>
                    <span><strong>Start Time: </strong><?php the_field('start_time');?></span><br>
                    <span><strong>Event Type: </strong><?php the_field('event_type'); ?></span><br>
                    <span><strong>Location: </strong><?php the_field('location')?></span>
                </div>
                <div class="event-description">
                <p><?php echo custom_field_excerpt(); ?></p>
                </div>
                </div>

            </div>    
            <?php endwhile; ?>
        </div>
        <?php 
    }
    wp_reset_query();//reset the global variable related to post loop
    $retVal = ob_get_contents();
    ob_end_clean();

    return $retVal;
}
Post a comment

comment list (0)

  1. No comments so far