Why Does get_page_by_title Return The Sample Post?
-
I’m trying to check if the page exists, if it’s published, and display a link if it does. Here’s my code:
<?php $page = get_page_by_title('Privacy Policy'); if ( get_post_status($page) === 'publish' ): ?> <li> <a href="<?php echo get_page_link( get_page_by_title('Privacy Policy') ); ?>">Privacy Policy</a> </li> <?php endif; $page = get_page_by_title('Terms of Use'); if ( get_post_status($page) === 'publish' ): ?> <li> <a href="<?php echo get_page_link( get_page_by_title('Terms of Use') ); ?>">Terms of Use</a> </li> <?php endif; $page = get_page_by_title('Terms of Use'); if ( get_post_status($page) === 'publish' ): ?> <li> <a href="<?php echo get_page_link( get_page_by_title('Sitemap') ); ?>">Sitemap</a> </li> <?php endif; ?>It displays the list items for pages that don’t exist with a link to the sample post. Why is it doing that?
- This topic was modified 3 years ago by .
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Why Does get_page_by_title Return The Sample Post?’ is closed to new replies.