get_post_type_archive_link( string $post_type ): string|false
- Since
- 3.1.0, 4.5.0
- Source
wp-includes/link-template.php:1301
Retrieves the permalink for a post type archive.
Parameters
$post_typestring- Post type.
Return
string|false- The post type archive permalink. False if the post type does not exist or does not have an archive.
Hooks fired · 2
2 hooks fire while get_post_type_archive_link() runs, in this order:
- apply_filters( post_type_archive_link )filterline 1320 (+19 into the body)
Filters the post type archive permalink.
- apply_filters( post_type_archive_link )filterline 1347 (+46 into the body)
Filters the post type archive permalink.
Uses · 7
- get_post_type_object()Retrieves a post type object by name.
- get_option()Retrieves an option value based on an option name.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- get_home_url()Retrieves the URL for a given site where the front end is accessible.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- user_trailingslashit()Retrieves a trailing-slashed string if the site is set for adding trailing slashes.
Used by · 10
- WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()Get the value emulated into a WP_Post and set up as a nav_menu_item.
- WP_Customize_Nav_Menus::load_available_items_query()Performs the post_type and taxonomy queries for loading available menu items.
- get_post_type_archive_feed_link()Retrieves the permalink for a post type archive feed.
- render_block_core_breadcrumbs()Renders the `core/breadcrumbs` block on the server.
- render_block_core_navigation_link()Renders the `core/navigation-link` block.
- render_block_core_navigation_submenu()Renders the `core/navigation-submenu` block.
- wp_admin_bar_edit_menu()Provides an edit link for posts and terms.
- wp_list_categories()Displays or retrieves the HTML list of categories.
- wp_nav_menu_item_post_type_meta_box()Displays a meta box for a post type menu item.
- wp_setup_nav_menu_item()Decorates a menu item object with the shared navigation menu item properties.
Source
function get_post_type_archive_link( $post_type ) { global $wp_rewrite; $post_type_obj = get_post_type_object( $post_type ); if ( ! $post_type_obj ) { return false; } if ( 'post' === $post_type ) { $show_on_front = get_option( 'show_on_front' ); $page_for_posts = get_option( 'page_for_posts' ); if ( 'page' === $show_on_front && $page_for_posts ) { $link = get_permalink( $page_for_posts ); } else { $link = get_home_url(); } /** This filter is documented in wp-includes/link-template.php */ return apply_filters( 'post_type_archive_link', $link, $post_type ); } if ( ! $post_type_obj->has_archive ) { return false; } if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { $struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; if ( $post_type_obj->rewrite['with_front'] ) { $struct = $wp_rewrite->front . $struct; } else { $struct = $wp_rewrite->root . $struct; } $link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); } else { $link = home_url( '?post_type=' . $post_type ); } /** * Filters the post type archive permalink. * * @since 3.1.0 * * @param string $link The post type archive permalink. * @param string $post_type Post type name. */ return apply_filters( 'post_type_archive_link', $link, $post_type );}History
Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
4.5.0
Support for posts was added.from the docblock
3.1.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.