Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've seen plenty of tutorials on how to get the ID of the upper-most parent, but I can't seem to find anything on how to get the ID from the direct parent.

Eg;

- Big John
  - Little John
    - Baby John

How, if I'm on the Baby John page, can I get the ID of Little John and not of Big John?

share|improve this question

2 Answers 2

I'm assuming that you're asking how to do it with code? (Doing it in backend is pretty easy - just try to edit parent page and see the ID in URL).

So how to check post parent in code? It's also very easy - direct parent is stored in post_parent property. If post has no parent, it will be 0.

So all you have to do is:

global $post;
$direct_parent = $post->post_parent;
share|improve this answer

$post->post_parent ?

http://codex.wordpress.org/Function_Reference/$post

share|improve this answer
1  
A better reference page might be WP_Post. –  Pat J Nov 18 '13 at 16:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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