Trying to get property of non-object in.. WordPress help :)


Ive been having some issues when in debug mode and not sure how to reolve them… this is the message i’m getting,

Notice: Trying to get property of non-object in /Users/MattStrange/Sites/pixelstores/wp-includes/post-template.php on line 29

It doesn’t get into specifics like what line number to fix but i have narrowed it down to do with get_the_ID();

For some reason WordPress doesn’t like the following,

function theme_scripts() {
	global $post, $pixelstore_mb_product;
	$productmeta = get_post_meta(get_the_ID(), $pixelstore_mb_product->get_the_id(), TRUE);	
	if (isset($productmeta['productgallery']) && $productmeta['productgallery'] == "Hover Zoom") {
		wp_enqueue_script( 'etalage', $script_folder . 'jquery.etalage.min.js', 'jquery');
add_action('wp_enqueue_scripts', 'theme_scripts');

Narrow down even more…

$productmeta = get_post_meta(get_the_ID(), $pixelstore_mb_product->get_the_id(), TRUE);	

Help appreciated.

I guess you are running theme_scripts function before creating $pixelstore_mb_product object. Or it may be a typo on $pixelstore_mb_product name.

post-template.php is reference to the $post,

    global $post, $pixelstore_mb_product;
    //check if post is object otherwise you're not in singular post
    if( !is_object($post) ) 

    $productmeta = get_post_meta(get_the_ID(), $pixelstore_mb_product->get_the_id(), TRUE); 

Ok, that works great PrimeThemes!

One thing though because i’m receiving these errors on the 404.php page i do not want the script to return as there are other stuff that needs to be loaded… for example… i’m using the custom fields to determine what styles are to be loaded… but becasue the 404.php page is automatically created there is no $post hence the error messages.

Maybe too complicated to understand :stuck_out_tongue: