AnswerBun.com

Trying to get property 'post_title' of non-object with

Stack Overflow Asked by German mazzaferro on January 1, 2022

PHP Notice: Trying to get property ‘post_title’ of non-object in line 217

Line 217:   <a href="'. (!$is_placeholder?$image[0]:'javascript:void(0);') . '" ' . (!$is_placeholder?' rel="prettyPhoto"':'') . '><img src="'. $image[0] . '" title="' . $value->post_title . '" style="height:80px;width:80px;"/></a>

Its been many years since I was a developer, so please don’t be mean, I need a hand with this.
This is wordpress 5.3.2 with woocommerce 4.0. Php 7.2 with cpanel in centOS

One Answer

Seems like your $value variable is not an instance of WP_Post.

If your code is inside the WP loop or in a single post or page, you can use get_the_title() instead of $value->post_title.

Else, you have to set the variable with the post, like this:

<?php $value = get_post(100); // change '100' with the right post ID ?>
<a href="'. (!$is_placeholder?$image[0]:'javascript:void(0);') . '" ' . (!$is_placeholder?' rel="prettyPhoto"':'') . '><img src="'. $image[0] . '" title="' . $value->post_title . '" style="height:80px;width:80px;"/></a>

Answered by Luca Rosaldi on January 1, 2022

Add your own answers!

Related Questions

Trying to get property ‘post_title’ of non-object with

1  Asked on January 1, 2022 by german-mazzaferro

   

Select max for a tuple in table

2  Asked on January 1, 2022 by maxsteel

         

bind python/flask module app yo WINDOWS Server IIS

1  Asked on January 1, 2022 by shaul-sondak

     

Break apart email attachment if zip is too big to email

0  Asked on January 1, 2022 by programmingislife

       

Retrieve previous position of an Image on refresh page

2  Asked on January 1, 2022 by roel-thijssen

 

EMP id Masking with asterisk inbetween string

2  Asked on December 30, 2021 by bala

   

Create Sidebar Nav menu

1  Asked on December 30, 2021

     

Avoid select from dual Union in PL/SQL

3  Asked on December 30, 2021 by alc

     

SQL pulling distinct values and creating an ID

2  Asked on December 30, 2021 by jamheadart

     

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP