Skip to content

TimberPost picks up the wrong post ID in preview mode #1318

@fregante

Description

@fregante

Steps to reproduce behavior

  1. Publish a post in the admin
  2. global $post->ID === 1 new TimberPost()->ID === 1
  3. Make change in post
  4. Click "Preview Changes" button
  5. global $post->ID === 1 new TimberPost()->ID === 2 <-- mismatch

Expected behavior

new TimberPost()->ID should be the same as global $post; $post->ID, which is the original post's ID

Actual behavior

new TimberPost()->ID is the revision/preview ID, not the original post's ID.

This causes new TimberPost()->thumbnail() to return nothing if the thumbnail was changed.

This fixes it for me:

global $post;
new TimberPost($post->ID);

What version of WordPress, PHP and Timber are you using?

PHP 5.5.37
WordPress 4.7.1
Timber 1.2.1

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)

Composer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions