How do I get a link to a WP page within a loop?

I'm trying to get a link to Page A within a loop on Page B. Normally I would use ?php echo get_page_link($mypage-ID); ? but the loop is causing this to always return a path to the current page.

Topic permalinks Wordpress

Category Web


So, it turns out that if you pass a Post or Page object to the_permalink() or get_page_link() it will override the post object set by the loop whereas passing an ID won't.

In the previous example you would use <?php echo get_page_link($mypage); ?> instead.

Source of get_page_link() had the answers: https://developer.wordpress.org/reference/functions/get_page_link/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.