I want to show a custom post type chosen from the meta box dropdown list but i am getting this error Notice: Trying to get property of non-object in C:\xampp\htdocs\wordpress\wp-content\themes\affiliator\footer.php on line 20 Here is my code:

$get_footer = get_post_meta( get_the_id(), 'af_choose_layout', true );

if( !empty( $get_footer ) ){
      $footer = get_post( $get_footer  );
      echo apply_filters('the_content',$footer->post_content);

So i just want to get the id of the custom post that can be usable for get_post(some id here...). Please help me to fix this

  • The get_the_id() function would return whatever the current post is. Maybe var_dump( $get_footer ) and ensure that it holds the expected value. – Howdy_McGee Apr 8 at 15:29
  • I have already checked $get_footer and it works fine, now i am going to try get_the_id(). – Ahtsham Ul Haq Apr 8 at 15:33
  • No luck with get_the_id(). – Ahtsham Ul Haq Apr 8 at 15:36
  • Maybe edit your question with all the details you currently have. For example, what specifically do you mean "no luck" with that function? Does it not return the right value? – Howdy_McGee Apr 8 at 15:37
  • Receiving no value with that even no error is showing. – Ahtsham Ul Haq Apr 8 at 15:51

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.