0

time. Last week I updated to version 7.0 of php and from there it is giving me the following errors:

Notice: Trying to get property 'ID' of non-object in web_URL/wp-content/themes/stellenportal/tool-box.php on line 33

Notice: Trying to get property 'post_author' of non-object in web_URL/wp-content/themes/stellenportal/tool-box.php on line 34

Here's my code:

at the beginning of the PHP file:

     $job_id       = isset( $_GET['job_id'] ) ? $_GET['job_id'] : false;

Line 32, Line 33:

     $job = get_post($job_id);
     $job_id = $job->ID;

Line 34

     if ( is_user_logged_in() && $current_user->ID === intval( $job->post_author ) || current_user_can( 'administrator' ) || is_admin() ) :

I have read that this is due to a change in php 7.2, but I do not give the correct form. Can somebody help me? Thank you

  • Your code has $job->ID;, but where is $job defined? – Jacob Peattie Feb 19 at 8:08
  • sorry, I have confused to place it. It is already edited – Dario B. Feb 19 at 8:12
  • Are you making sure to not try get_post( $job_id ) if $job_id is false. The reason these errors are occurring is because that line is not returning a post object, because it doesn't exist. You should make sure that it returns a valid result before attempting to use its properties like $job->ID. It wouldn't have anything to do with PHP 7.2. – Jacob Peattie Feb 19 at 8:15
  • @JacobPeattie I tried a var_dump($job_id); , and I receive a string (4) "news1",this means that $ job_id contains a result – Dario B. Feb 19 at 8:36
  • news1 Is not a valid post ID. get_post() requires the integer ID for a post. – Jacob Peattie Feb 19 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.