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?
wp_get_post_parent_id( int|WP_Post|null $post = null ): int|false. Returns the ID of the post's parent.
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.
try something like this
global $post;
if ($post->post_parent == 10) {
echo "parent's id is 10";
}
$id = wp_get_post_parent_id( get_the_id() );
Now $id
has parent page id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With