Skip to content

Commit da96f08

Browse files
committed
ref #521 -- fixed error in older versions of WP with get_the_ID()
1 parent 0162265 commit da96f08

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

lib/timber-post.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ protected function determine_id($pid) {
5555
} else if ($wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) {
5656
//hack for static page as home page
5757
$pid = $wp_query->queried_object_id;
58-
} else if ($pid === null && get_the_ID()) {
59-
$pid = get_the_ID();
60-
} else if ($pid === null && ($pid_from_loop = TimberPostGetter::loop_to_id())) {
58+
} else if ($pid === null) {
59+
$gtid = false;
60+
$maybe_post = get_post();
61+
if (isset($maybe_post->ID)){
62+
$gtid = true;
63+
}
64+
if ( $gtid ) {
65+
$pid = get_the_ID();
66+
}
67+
}
68+
if ($pid === null && ($pid_from_loop = TimberPostGetter::loop_to_id())) {
6169
$pid = $pid_from_loop;
6270
}
6371
return $pid;

0 commit comments

Comments
 (0)