WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

#34428 closed enhancement (wontfix)

New function `has_archive_post_type()`

Reported by: sebastian.pisula Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

Function will be check that custom post type has archive. For example:

<?php if(has_archive_post_type('cpt')) : ?>
<a href="<?php echo get_post_type_archive_link('cpt');?>">My Special Archive Link</a>
<?php endif;?>

Attachments (1)

34428.patch (854 bytes) - added by sebastian.pisula 5 years ago.

Download all attachments as: .zip

Change History (3)

#1 @swissspidy
5 years ago

get_post_type_archive_link returns false when a post type doesn't have an archive. You could just do:

<?php if( get_post_type_archive_link( 'cpt' ) ) : ?>
<a href="<?php echo get_post_type_archive_link( 'cpt' ); ?>">My Special Archive Link</a>
<?php endif; ?>

#2 @swissspidy
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Closing as per my last comment.

Note: See TracTickets for help on using tickets.