Skip to content

Instantly share code, notes, and snippets.

@jamesmehorter
Last active August 29, 2015 14:22
Show Gist options
  • Save jamesmehorter/244c1c9922e3c0629437 to your computer and use it in GitHub Desktop.
Save jamesmehorter/244c1c9922e3c0629437 to your computer and use it in GitHub Desktop.
Get permalink of page using a specific page template
$wire_page_permalink = "";
// Fetch the page using the wire page template
$wire_page = get_pages( array(
'meta_key' => '_wp_page_template',
'meta_value' => 'template-the-wire.php'
) );
// Fetch the wire page permalink
if ( ! empty( $wire_page ) && 0 < count( $wire_page ) ) :
$wire_page_permalink = get_permalink( $wire_page[0]->ID ) ;
endif;
// Usage
if ( ! empty( $wire_page_permalink ) ) : ?>
<?php echo $args['before_title']; ?>
<a href="<?php echo esc_url( $wire_page_permalink ); ?>">
<?php echo esc_html( $title ); ?>
</a>
<?php echo $args['after_title']; ?>
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment