WordPress.org

Ready to get started?Download WordPress

Forums

Trying to get property of non-object (5 posts)

  1. contempoinc
    Member
    Posted 2 years ago #

    With WP_DEBUG on I'm getting the following error on the code snippet below:

    Notice: Trying to get property of non-object in C:\wamp\www\wordpress\wp-content\themes\executive\admin\theme_functions.php on line 569

    Line 569 is the $photos = get_children…

    function ct_get_post_image() {
    	global $post;
    	$photos = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
    	if ($photos) {
    		$photo = array_shift($photos);
    		return wp_get_attachment_url($photo->ID);
    	}
    	return false;
    }
    $photo = ct_get_post_image();

    Can't seem to find any solution, any help is appreciated.

  2. justinshattuck
    Member
    Posted 2 years ago #

    Chris,

    it looks like its the array object, shouldn't it be order_by? Haven't built up a query string that big in a while ;)

  3. justinshattuck
    Member
    Posted 2 years ago #

    its becuse of the $post->ID, its coming back NIL. Its coming back null which is causing the error trigger.

  4. justinshattuck
    Member
    Posted 2 years ago #

    Chris,

    var_dump or print_r $post and see if its even in the object. Check the globals too ;)

  5. contempoinc
    Member
    Posted 2 years ago #

    Whats odd is the code works, just throws the error when WP_DEBUG is on

Topic Closed

This topic has been closed to new replies.

About this Topic