WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 16 months ago

#42534 closed defect (bug) (worksforme)

get_post_time is adding or dropping a day on the front end.

Reported by: keyinora Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9
Component: Date/Time Keywords: reporter-feedback
Focuses: rest-api, performance Cc:
PR Number:

Description

Hello,

I found this bug when using (get_post_time), i have two examples 1. the normal way of pulling post through a theme and 2. pulling post through the rest api.

the issue is as followed:

  1. if on post archive or home, the first item will have either (and this part changes) a +1 or -1 to the day the post was submitted, but only the first post
  2. if i pull the post through the REST API, it does it to all post.

I have not tried every format, but the one i tried was this get_post_time(‘F d, Y’, true);

Please advice if i need to provide any additional details!

Attachments (1)

timezone-settings.PNG (31.1 KB) - added by keyinora 2 years ago.
Time Zone Settings

Download all attachments as: .zip

Change History (5)

#1 @petertoi
2 years ago

  • Keywords reporter-feedback added

Hi @keyinora - thanks for submitting a ticket!

I was just trying to replicate the bug you described in your ticket but having some difficulty. Would you mind providing us with some more details?

Can you perhaps provide some code fragments, or screenshots that illustrate the problem?

Also, could you provide some information about your time zone settings?

When you refer to "the day the post was submitted" are you referring to your local day/time? Or GMT day/time. In the call to get_post_time() I see that you're setting the $gmt flag to true which may be causing the difference? Let's get more details and find out for sure.

@keyinora
2 years ago

Time Zone Settings

#2 @keyinora
2 years ago

Sure no problem, i have attached a screenshot of my timezone settings, please let me know if you don't see it!

Here is the home.php basic code i have, you will see i call a template of "templates/archive-post" to retrieve a template of the repeated code.

<?php
                        <?php if (have_posts()) : while (have_posts()) : the_post();
                                get_template_part( 'templates/archive-post' );?>
                        <?php endwhile;endif;?>
                        <?php get_template_part( 'templates/pagination' );?>

Here is my template code.

<?php
<?php 
        $bot_timestamp = get_post_time('Y-m-d',  true);
        $user_timestamp = get_post_time('F j, Y', true);
        $author = get_the_author();
?>
<article id="blog-<?php the_ID();?>" class="row top-xs center-xs start-md">
        <figure class="col-xs-12 col-md-3">
                <?php if (has_post_thumbnail()): ?>
                <?php the_post_thumbnail('medium', array('alt' => esc_attr(get_the_title()), 'title'=> esc_attr(get_the_title()), 'class'=>'img-circle')); ?>
                <?php else: ?>
                <?php $image = gfield('default_blog_image', 'options'); ?>
                <img class="img-circle" src="<?php echo $image['sizes']['medium']; ?>" width="<?php echo $image['sizes']['medium-width']; ?>" height="<?php echo $image['sizes']['medium-height']; ?>" alt="<?php echo $image['alt']; ?>" title="<?php echo $image['title'] ?>" />
                <?php endif; ?>
        </figure>
        <div class="col-xs-12 col-md-9">                
                <h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <h6><time datetime="<?php echo $bot_timestamp; ?>"><?php echo $user_timestamp; ?></time></h6>
                <?php the_excerpt(); ?>
        </div>
</article>

Let me know if i need to provide additional information!

#3 @petertoi
2 years ago

@keyinora thanks!

Can you show me how the submitted date is different from the template/REST date? Are the Published Dates in the wp-admin WP_Post_Table accurate? I do see that your template is displaying time in UTC, not in local time. Could that account for the difference?

Perhaps you can upload a screenshot of the same post from wp-admin showing the date as well as rendered in the template and in the REST API to show how they are different?

Also, can you confirm the version of WordPress your using? If version 4.9, which build are you using?

Last edited 2 years ago by petertoi (previous) (diff)

#4 @Rarst
16 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Insufficient details to reproduce unfortunately, closing as stalled for now.

Note: See TracTickets for help on using tickets.