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/
Related Posts:
- Strange permalink issue: can’t rename /company-2/ to /company/
- How to get permalink and title from post ID?
- Pretty permalinks for search results with extra query var
- Using $_GET variables in the URL?
- Removing leading zeros from custom permalink structure
- How can I include a query string with get_permalink
- Post being redirected to attachment post
- Without index.php in permalinks I get 404 across site
- Changing Permalinks to a Custom Permalink causes a 404 Error [no matter what I do]
- How to assign a Permalink to a Function
- Redirect user if it’s not logged in
- Random Alphanumeric Key URLs
- Date archive permalink modification
- How to get this JavaScript working with get_permalink
- Add a css class to a taxonomy permalink
- Change of permalink structure – redirects in htaccess breaks the archive links
- Change permalinks with ACF values
- Changing Custom Permalink with Filter
- Filter string like a slug
- 404 with post name permalinks
- Should there be a trailing slash in the permalink
- Link to external URL
- Confusion about how a URL is being parsed
- Woocommerce Product Attribute Permalink doesn’t work?
- Problem with wordpress links on a live site
- Permalink change redirects by WordPress [duplicate]
- WPML get permalink to the translated post from the original post
- page nested 3 levels deep shows 404
- Removing /author/ slug from URL gives 404
- Add custom post type name in term link?
- Can I create permalinks like this: /%post_type%/%postname%/
- Why the “Permalink” option is not showing in the “Settings”? [closed]
- How to get the full URL of the current page and change domain of it?
- Custom permalink structure: /%custom-taxonomy%/%post-name%/ (without CPT slug)
- get_permalink() is not working after published
- How can I get this custom post type permalink structure? %custom_post_type%-%taxonomy%-%term-postname%
- get_permalink returning site home url instead of the url of slug being passed
- WordPress add_rewrite_tag working for Posts, but not working for Pages
- Host frontpage via example.com and everything else via example.com/blog
- WordPress can generate numeric permalinks, which then 404
- 404 error using Meta for Permalink rewrite
- Permalink changes gives me 404 [closed]
- How do I make 301 redirection from `/%post_id%/` to `/%postname%/`?
- WordPress suddenly changed all links to example.com/example.com/
- How to handle paging/pagination with a custom permalink?
- Environment independent way to link to certain pages on frontend
- Using one slug/post-name for multiple pages
- Custom URL rewrites for templates
- Gutenberg output URL to post from attribute with post ID
- Broken wordpress site, non-working links and no access to wp-admin page
- How can I get the list of all pages URLs including their shortlink IDs?
- How to change custom post type, blog post and page permalink by template?
- How to use Specific URLs for some posts
- Change permalinks for specific pages
- How can you create a Permalink structure on a WordPress site?
- WordPress Permalink
- How to replace permalinks
- Multiple Tags Issue in Permalinks
- Auto Changing Text Case
- Is it possible to change the permalink structure without changing the old permalinks to posts and without 301 redirects?
- Keep wordpress basic permalink preferences
- Adding a ‘blogs’ prefix in the URL structure but only for blogs
- .htaccess to redirect to a wp page
- How to redirect old permalinks to ones generated by [WP-Hashed-ID] plugin?
- How do I use the same Tag slug for different Tags?
- Replacing + sign to – in wp Search Permalink
- Permalinks are not working in WordPress
- How to create a standard WP Page that has the same url as an archive
- One post but two separate permalink structure and template views
- permalinks constantly needs re-saving
- Link to a custom page without a permalink?
- Retain Post title keywords in URL even if user changes post title or any other way to achieve SEO friendly permalink?
- How to change the URL using rewrite rule in wordpress
- Permalink not working in Apache on Linux
- HTTPS permalinks resulting in 404
- Changing Permalinks. Old links don’t work
- WP Job Manager Custom Permalink Returns 404 Errors
- How to make custom page link to root automatically?
- Automatically remove repeated words in slug
- Permalinks – Archives
- Dynamically populate permalinks
- When using number in url it is redircting to same page but when using character it redirects to 404
- Change Image depending on page path
- WordPress Permalinks 404 error
- Webdav with permalink in WordPress v3.3.1
- ReWrite Permalink to New Permalink Nginx
- Permalinks of archive tag wordpress
- Why not working /%postname%/ with ajax serverinterval?
- Custom Permalink Base
- What is the best way to insert links indepently of the permalink structure?
- Appending a variable to RSS link url
- My wordpress site must be being affected by outside sources [duplicate]
- Hyperlinking images on posts to permalink
- Choose template depending on URL
- Create a permalink for a post’s attachments
- Permalinks not working after Migration – AllowOverride All, htaccess set
- Can I specify template to use with the_permalink?
- Can’t find permalinks section under “Settings”?
- Add additional URL variations for a Post
- How to use ‘blogs.dir’ as media upload instead of ‘uploads’ directory in WordPress multisite setup