wppaste
WordPress

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:

  1. apply_filters( post_type_archive_link )filterline 1320 (+19 into the body)

    Filters the post type archive permalink.

  2. 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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.