0

I use this code on post template (single.php) to check if current post is sticky:

<?php
if ( is_sticky() )
echo 'Post is sticky.';
?>

But it is not working on attachment page template (image.php). I wish to check if parent post is sticky on attachment page of post featured image.

How to check if parent post is sticky on attachment page (image.php)?

1 Answer 1

3

The post parent can be accessed by $post->post_parent. The ID of the post parent is retrieved, so can try something like this

$parent_ID = $post->post_parent;
if( is_sticky( $parent_ID ) ) {

    // DO SOMETHING IF POST PARENT IS STICKY

}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.