I have several pages with a parent. So, $post->post_parent should be different than 0, right?

echo $post->post_parent;

Is returning 0.

Thing is, this is only happening in one post category. Do I need to declare that a page has a parent elsewhere? I do it from within the edit page form of that page.


  • 1
    I'm not sure what exactly you are asking. What category? What code precedes the line you included? Please modify your question to include additional details.
    – Dan
    Mar 31, 2014 at 21:31
  • Can you post the page code? That may be helpful to pinpoint the problem.
    – Howdy_McGee
    Mar 31, 2014 at 21:44
  • Yes, a child page should have a parent ID other than 0. Something is wrong with your site but the information provided is not sufficient to reveal what. Do you have any plugins installed? What is your theme?
    – s_ha_dum
    Mar 31, 2014 at 21:52
  • You're probably not globalizing $post before you try to call it. Ensure debug mode is enabled, and report any PHP notices generated. Also: please edit your question to include your actual code, in context. Mar 31, 2014 at 22:01
  • "I have several pages with a parent." - What makes you believe that this is true?
    – user27457
    Apr 3, 2014 at 22:15

2 Answers 2


Try echoing serialized($post); to make sure you're looking at the right page(s). It should return the post_parent so the problem may be either in the call you're making to get $post, or double-check that the set of pages did save with a parent page.

Easiest way of doing that is call up "All Pages" and they'll be indented under the appropriate parent if they're set up correctly (otherwise opening each one and looking).


yes. It should be different. For child the value will be 316.

  • 2
    Please read How to Answer. Then improve your answer.
    – fuxia
    May 28, 2015 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.