Quicky

Notice: Object of class WP_Post could not be converted to int in /app/public/wp-includes/general-template.php

June 23, 2019 /1 min read

I faced this error while working on a project and it wasted some of my time to figure out why it was happening. I had the following code.

$pages = get_pages();

if( is_array( $pages ) && count( $pages ) > 0 ) {
	foreach ( $pages as $page ) {
		// Some stuff I am planning to do
		}
	}
}

It gave me the following error and it was not clear about its location which makes it a bit harder to figure out when I was not working on the file having that code done a while ago.

Notice: Object of class WP_Post could not be converted to int in /app/public/wp-includes/general-template.php on line 1098

It looks like the variable name $page is reserved. Anyways, I changed the code to the following which fixed the issue.

$all_pages = get_pages();

if( is_array( $all_pages ) && count( $all_pages ) > 0 ) {
foreach ( $all_pages as $single_page ) {
// Some stuff I am planning to do
}
}
}


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Let's build something exceptional.

I'm selectively available for consulting, security audits, plugin architecture, and product development partnerships. If you're building something that demands engineering excellence, I'd love to hear about it.

Looking for a detailed project estimation? Use Wizard

Fun Portfolio Projects

Cli Folio Comicbook Desktop Factory Game Folio Toons Folio
Hassan Raza