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 have a template which outputs the blog posts (Blog Page), I open one of the posts which use single.php template, Now how can I get the ID of it's parent which is the (Blog Page)?

I should say that I want to use this ID to get the meta box value of the blog page in single.php.

The same goes for a custom post type, let's say 'project', Where a page template list the project's posts (Projects Page) and single-project.php for the single project post. in this case I want to get the (Projects Page) ID in single-project.php.

share|improve this question
1  
Can you explain the situation, Why do you want to get it? –  Vinod Dalvi Apr 25 '13 at 7:11
    
Post's parent id is not a blog page, but another post. There is no relation between post and your blog page, –  Rajeev Vyas Apr 25 '13 at 7:12
    
@VinodDalvi I edited the queston. –  metalzade Apr 25 '13 at 7:24
    
@RajeevVyas so you're saying there is no way to get the ID of blog page? –  metalzade Apr 25 '13 at 7:24
    
@metalzade offcourse not, try using get_option('page_for_posts') or see the is_home function from codex for reference. –  Rajeev Vyas Apr 25 '13 at 7:37
show 7 more comments

1 Answer

Use $post->post_parent to get the parent ID of the post. Here $post is an object with properties.

share|improve this answer
    
I was able to get the ID of the blog page by get_option('page_for_posts') but no success in custom post type as $post->post_parent returns 0. –  metalzade Apr 25 '13 at 8:09
    
$post->post_parent is working for me. print your $post object,then you will there is [post_parent] is there. –  saifur Apr 25 '13 at 11:42
add comment

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.