Jump to content

Archived

This topic is now archived and is closed to further replies.

pealo86

Wordpress: get_page_by_title() generating PHP error after upgrading PHP

Recommended Posts

I've recently had my hosts upgrade PHP on my server to 5.2.17

 

Since that time, I am no longer able to use the get_page_by_title() function on my Wordpress Multisite.

 

Whereever that function is used, I get an error like the following:

Catchable fatal error: Object of class stdClass could not be converted to string in /var/www/vhosts/ ...

 

If I remove that function in particular, the error goes away. So there's obviously just something about the server configuration that doesn't like this function, though I have no idea what!

 

Has anyone else had this problem? I've had a very hard time finding similar problems on Google

Share this post


Link to post
Share on other sites

Here's the code for the function.  Check this against the code for your wordpress install.  Are you using a current version or an old one? 

I would personally suggest putting in some debugging code to figure out what is going on.  As you can see it's a pretty simple function that calls a few other functions, which could be having issues.  I don't know what would happen if you encountered a database error here, say if the structure doesn't match the query.

 

In particular, there is a parameter in this function ($output) that can control the type of return value.  It is possible that your template code is expecting an array, and getting an object instead. 

 

/**
* Retrieve a page given its title.
*
* @since 2.1.0
* @uses $wpdb
*
* @param string $page_title Page title
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT.
* @param string $post_type Optional. Post type. Default page.
* @return mixed
*/
function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) {
global $wpdb;

$page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) );
if ( $page )
	return get_page($page, $output);

return null;
}

Share this post


Link to post
Share on other sites

Ohhh I see! Thanks for the tip, funnily enough I just had to fix it using some other workaround (e.g. scrapping the template tag and finding another way of doing it).

 

But I'll keep this in mind for next time ;) If there is a next time!

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.