get_post_type_archive_link()
Returns the URL (permalink) to the archive page of a custom post type.
For more details on which pages relate to "post_type_archive," see the description of the function is_post_type_archive()
If the function does not work or returns false, check if the argument has_archive => true is enabled when registering the post type.
Hooks from the function
Returns
String|false. String: a link (URL) to the archive page of the specified post type. Will return false if the specified post type does not exist or if the has_archive parameter is not set for it.
If post is specified, it will return a link to the site's homepage or to the page specified in the admin as the "Posts page."
Usage
get_post_type_archive_link( $post_type );
- $post_type(string) (required)
- The name of the custom post type.
Examples
#1 Link to the archive page of the custom post type
Let's say we created a post type book with register_post_type(). Let's display a link to an archive page of this type (page with all posts of this type):
<a href="<?php echo get_post_type_archive_link('book'); ?>">Books</a>
Notes
- Global. WP_Rewrite.
$wp_rewriteWordPress rewrite component.
Changelog
| Since 3.1.0 | Introduced. |
| Since 4.5.0 | Support for posts was added. |