Make WordPress Core

Opened 18 months ago

Last modified 16 months ago

#59014 new defect (bug)

PHP Fatal error in post-template.php

Reported by: volqld's profile volqld Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 6.3
Component: Posts, Post Types Keywords: needs-patch
Focuses: template Cc:

Description (last modified by sabernhardt)

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

Change History (1)

#1 @sabernhardt
16 months ago

  • Component changed from General to Posts, Post Types
  • Description modified (diff)
Note: See TracTickets for help on using tickets.