[wp-trac] [WordPress Trac] #59014: PHP Fatal error in post-template.php
WordPress Trac
noreply at wordpress.org
Tue Oct 31 00:34:33 UTC 2023
#59014: PHP Fatal error in post-template.php
-------------------------------+------------------------------
Reporter: volqld | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 6.3
Severity: minor | Resolution:
Keywords: needs-patch | Focuses: template
-------------------------------+------------------------------
Changes (by sabernhardt):
* component: General => Posts, Post Types
Old description:
> Hi there,
>
> I hope this email finds you well. Unfortunately, we've recently
> encountered a critical error that requires immediate attention. This
> issue pertains to the single page templates, specifically an example like
> this: https://volunteeringqld.org.au/governance/before-you-join/. The
> error was not present a week ago, and we're currently grappling to
> determine its cause. This problem was initially observed on both WP6.22
> and WP6.3.
>
> The post https://volunteeringqld.org.au/governance/before-you-join/
> conncted to a singletemplate php mytemplate/single-governance-before-you-
> join.php, what calls <?php the_content() ?> what throws error "There has
> been a critical error in this website" and output steam finishes. Log
> error gives this line:
> "PHP message: PHP Fatal error: Uncaught TypeError: Unsupported operand
> types: WP_Post - int in /home/vqadmin/public_html/wp-includes/post-
> template.php:330Stack trace:#0 /home/vqadmin/public_html/wp-includes
> /post-template.php(247): get_the_content()#1 /home/vqadmin/public_html
> /wp-content/themes/volunteeringAU/single-governance-before-you-
> join.php(411): the_content()#2 /home/vqadmin/public_html/wp-includes
> /template-loader.php(106): include('...')#3 /home/vqadmin/public_html/wp-
> blog-header.php(19): require_once('...')#4
> /home/vqadmin/public_html/index.php(17): require('...')#5 {main} thrown
> in /home/vqadmin/public_html/wp-includes/post-template.php on line 330',
> referer: https://volunteeringqld.org.au/governance/"
>
> To address this, we have applied the following code snippet in post-
> template.php line 330:
> if( ! is_int($page_no)) {
> $page_no = 1; // Igor
> //echo '<!--'.print_r( $elements, true ). '-->';
> }
>
> When echo ancommented it gives
> Array
> (
> [page] => WP_Post Object
> (
> [ID] => 5
> [post_author] => 7
> [post_date] => 2021-10-21 04:24:08
> [post_date_gmt] => 2021-10-21 04:24:08
> [post_content] =>
> [post_title] => Home
> [post_excerpt] =>
> [post_status] => publish
> [comment_status] => closed
> [ping_status] => closed
> [post_password] =>
> [post_name] => home
> [to_ping] =>
> [pinged] =>
> [post_modified] => 2023-05-26 13:50:03
> [post_modified_gmt] => 2023-05-26 03:50:03
> [post_content_filtered] =>
> [post_parent] => 0
> [guid] => https://volunteeringqld.org.au/?page_id=5
> [menu_order] => 0
> [post_type] => page
> [post_mime_type] =>
> [comment_count] => 0
> [filter] => raw
> )
>
> [more] => 1
> [preview] =>
> [pages] => Array
> (
> [0] => <!-- wp:paragraph -->
> <p><strong>Achieving a good transition to the next volunteer who will
> take over from you has benefits for you, the organisation, and the
> incoming governance member. Let’s explore things you can do to ensure a
> good handover.</strong></p>
> <!-- /wp:paragraph -->
>
> <!-- wp:paragraph -->
> <p>In this stage of your Governance journey we explore:</p>
> <!-- /wp:paragraph -->
> )
>
> [multipage] => 0
> )
>
> As you can see, instead of having 1 in $elements['page'], it contains a
> WP_Post object of the very first post from the database, even not the one
> that is displayed.
>
> We are hopeful that this information helps you in resolving the issue and
> that a solution will be included in an upcoming patch. Please don't
> hesitate to reach out if you require more details or assistance.
>
> Best regards,
> Igor
New description:
Hi there,
I hope this email finds you well. Unfortunately, we've recently
encountered a critical error that requires immediate attention. This issue
pertains to the single page templates, specifically an example like this:
https://volunteeringqld.org.au/governance/before-you-join/. The error was
not present a week ago, and we're currently grappling to determine its
cause. This problem was initially observed on both WP6.22 and WP6.3.
The post https://volunteeringqld.org.au/governance/before-you-join/
connected to a single template php `mytemplate/single-governance-before-
you-join.php`, what calls `<?php the_content() ?>` what throws error
"There has been a critical error in this website" and output steam
finishes. Log error gives this line:
{{{
"PHP message: PHP Fatal error: Uncaught TypeError: Unsupported operand
types: WP_Post - int in /.../wp-includes/post-template.php:330
Stack trace:
#0 /.../wp-includes/post-template.php(247): get_the_content()
#1 /.../wp-content/themes/volunteeringAU/single-governance-before-you-
join.php(411): the_content()
#2 /.../wp-includes/template-loader.php(106): include('...')
#3 /.../wp-blog-header.php(19): require_once('...')
#4 /.../index.php(17): require('...')
#5 {main} thrown in /.../wp-includes/post-template.php on line 330',
referer: https://volunteeringqld.org.au/governance/"
}}}
To address this, we have applied the following code snippet in `post-
template.php` line 330:
{{{
if( ! is_int($page_no)) {
$page_no = 1; // Igor
//echo '<!--'.print_r( $elements, true ). '-->';
}
}}}
When echo ancommented it gives
{{{
Array
(
[page] => WP_Post Object
(
[ID] => 5
[post_author] => 7
[post_date] => 2021-10-21 04:24:08
[post_date_gmt] => 2021-10-21 04:24:08
[post_content] =>
[post_title] => Home
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => home
[to_ping] =>
[pinged] =>
[post_modified] => 2023-05-26 13:50:03
[post_modified_gmt] => 2023-05-26 03:50:03
[post_content_filtered] =>
[post_parent] => 0
[guid] => https://volunteeringqld.org.au/?page_id=5
[menu_order] => 0
[post_type] => page
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[more] => 1
[preview] =>
[pages] => Array
(
[0] => <!-- wp:paragraph -->
<p><strong>Achieving a good transition to the next volunteer who will take
over from you has benefits for you, the organisation, and the incoming
governance member. Let’s explore things you can do to ensure a good
handover.</strong></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>In this stage of your Governance journey we explore:</p>
<!-- /wp:paragraph -->
)
[multipage] => 0
)
}}}
As you can see, instead of having 1 in `$elements['page']`, it contains a
`WP_Post` object of the very first post from the database, even not the
one that is displayed.
We are hopeful that this information helps you in resolving the issue and
that a solution will be included in an upcoming patch. Please don't
hesitate to reach out if you require more details or assistance.
Best regards,
Igor
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59014#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list