I’m trying to write an if statement where, if a child page’s has a slug equal to a specific value, a different statement is echoed. Regardless of the slug value, the function always returns the else value rather than any other.
<?php
global $post;
$post_data = get_post($post->post_parent->post_name);
if ($post_data == 'slug-one'){
$ticket = 'Cats';
} elseif ($post_data == 'slug-two') {
$ticket = 'Dogs';
} else {
$ticket = 'Birds';
}
echo $ticket;
?>
Any ideas as to how I can better write the statement, or what the error occurring is?
As it turns out, I shouldn’t have called
$post_data = get_post($post->post_parent->post_name)
. My fixed code is below. Thanks for the advice everyone.