-
-
Notifications
You must be signed in to change notification settings - Fork 513
Timber::get_post returns a Timber\Post object even when the post ID doesn't exist #1467
Copy link
Copy link
Closed
Labels
Description
Expected behavior
Timber::get_post() on a non-existent post ID should return null (like the native WordPress get_post() function) or at least some kind of falsey value to allow easy conditionals.
Actual behavior
A less-than-useful, mostly empty Timber\Post object is returned. For example:
>>> Timber::get_post('1312312');
=> Timber\Post {#1461
+ImageClass: "Timber\Image",
+PostClass: "Timber\Post",
+TermClass: "Timber\Term",
+object_type: "post",
+class: "",
+id: null,
+ID: "1312312",
+post_author: null,
+post_content: null,
+post_date: null,
+post_excerpt: null,
+post_parent: null,
+post_status: null,
+post_title: null,
+post_type: null,
+slug: null,
}
Steps to reproduce behavior
Call Timber::get_post() on a nonexistent post ID. It does seem to check if the value is numeric -- a non-numeric string returns null.
What version of WordPress, PHP and Timber are you using?
WordPress 4.8, PHP 5.6, Timber 1.3.2
How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)
Installed using Composer
Reactions are currently unavailable