Support

Account

Home Forums Backend Issues (wp-admin) Null value outside the loop

Helping

Null value outside the loop

  • Hi, what’s wrong in the above code?
    Im trying to pass a variable outside the loop but I get this error:

    Trying to get property ‘numero_doc’ of non-object

    $posts = new WP_Query( $args );
    
    if( $posts ):
    
     foreach( $posts as $post ): 
            
           setup_postdata( $post );
    
    $number = $post->numero_doc;
    
    endforeach;
    wp_reset_postdata();
    endif;
    
    }
     $field['default_value'] = $number + 1;
      return $field;
    }
  • What do you think that $post->numero_doc should be?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.