0

So we recently noticed that the post date on our posts is showing up as the current date.

For example here: https://www.chrisapappas.com/2019/02/11/grammys-2019-best-dressed/.

All our posts are like this. And it is only happening on the front end (back end is fine) and it only shows up incorrectly in the individual posts and not in the archive.

I asked our host, WPEngine, and they think it might be that a part of the code is not compatible with PHP 7.2 and the issue may have been due to the upgrade. Since I didn't make this theme and I'm not that well-versed in PHP, I've been looking at this for a long time with no solution.

This is some code I found which may be causing the issue...

This is the code in single.php:

$context                 = Timber::get_context();
$post                    = Timber::query_post();
$context['timberPost']   = $post;
$context['post']         = getSinglePost('post', $post->ID);
$context['comment_form'] = TimberHelper::get_comment_form();
$context['instagram']    = $instagramCachedResults;
if (post_password_required($post->ID)) {
Timber::render('single-password.twig', $context);
} else {
Timber::render(array('single-' . $post->ID . '.twig', 'single-' . 
$post->post_type . '.twig', 'single.twig'), $context);

In a file called functions--custom-posts.php I see this code:

function getSinglePost($posttype = null, $id = null)
{
if ($id != null) {
    $postId = $id;
} else {
    $postId = get_the_id();
}

$attachedimage = new TimberImage(get_post_thumbnail_id());
$categories    = get_the_category();

// setup an array to change the post data returned
$singlePostArray = array(
    'date'       => strtotime(get_the_date()),
    'id'         => get_the_id(),
    'title'      => get_the_title(),
    'categories' => $categories,
    'content'    => get_the_content(),
    'excerpt'    => get_the_excerpt(),
    'tags'       => get_the_tags(),
    'post_type'  => $posttype,
    'image'      => $attachedimage,
    'link'       => get_permalink(),
);
if ($posttype == 'post') {
    $singlePostArray['custom'] = prepareBlogPostFields();
}

// Restores original Post Data
wp_reset_postdata();

return $singlePostArray;
}

There are some PHP warnings for this theme as well:

PHP Warning:  filectime(): stat failed for /nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/api-cache.json in /nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/instagram.php on line 33
Warning: filectime(): stat failed for /nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/api-cache.json in /nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/instagram.php on line 33
PHP Warning:  file_get_contents(https://api.instagram.com/v1/users/1546007036/media/recent/?access_token=1546007036.1677ed0.08755b3609e844fbbe87f7ee6498185b): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
 in /nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/instagram.php on line 9
Warning: file_get_contents(https://api.instagram.com/v1/users/1546007036/media/recent/?access_token=1546007036.1677ed0.08755b3609e844fbbe87f7ee6498185b): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
 in /nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/instagram.php on line 9
PHP Warning:  unlink(/nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/api-cache.json): No such file or directory in /nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/instagram.php on line 54
Warning: unlink(/nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/api-cache.json): No such file or directory in /nas/content/live/chrisastaging/wp-content/themes/chrisapappas/library/instagram.php on line 54

Any help is appreciated! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.