Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If page parent equals ID (number)?

Tags:

php

wordpress

I have an if statement that is checking the ID of the page, using the following:

<?php if ( is_page(10) ) { ?>

How can I do something like if page parent is 10?

like image 807
Rob Avatar asked Jan 15 '13 10:01

Rob


People also ask

How do I find the parent ID in WordPress?

wp_get_post_parent_id( int|WP_Post|null $post = null ): int|false. Returns the ID of the post's parent.

Is Page A parent WordPress?

A WordPress parent page is a top-level page in the site's hierarchy. The group of sub-pages nestled under it are called child pages.


2 Answers

try something like this

global $post;

if ($post->post_parent == 10) {
   echo "parent's id is 10";
}
like image 184
Reigel Avatar answered Oct 01 '22 19:10

Reigel


$id = wp_get_post_parent_id( get_the_id() );

Now $id has parent page id

like image 22
suraj singh Avatar answered Oct 01 '22 19:10

suraj singh