Create an if is_page statement based on parent page

Question

I am trying to show something in a template based on what page is showing. This is working fine until I want to show a part of the template based on whether the parent post page slug is ‘courses’.

So the page url ends in ‘.com/courses/course-1’ so I want specific code to show for all posts where the post parent slug is ‘courses’

I have tried the following:

global $post;
$post_data = get_post($post->post_parent);

<?php if ( is_page( array( 'learn', 'profile') )  || ($post_data->post_parent == 'courses') ) { ?>

THINGS GO HERE 

<?php } ?>

but for some reason once I add the code || ($post_data->post_parent == 'courses') the if statement is then ignored on the template. The result is that even if a page not listed in the array, the ‘THINGS GO HERE’ is generated anyway.

What am I doing wrong?

0
Hana Fejzic 2 months 0 Answers 10 views 0

Leave an answer