Created
July 5, 2017 09:50
-
-
Save Narayon/4b8b1d92ff24e06df20365e1d3a8a9e3 to your computer and use it in GitHub Desktop.
WP - Get link of page with specific template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_template_page_url( $template_name ) { | |
$url = null; | |
$pages = new \WP_Query( array( | |
'post_type' => 'page', | |
'meta_key' => '_wp_page_template', | |
'meta_value' => $template_name, | |
) ); | |
// cycle through $pages here and either grab the URL | |
// from the results or do get_page_link($id) with | |
// the id of the page you want | |
if ( isset( $pages[0] ) ) { | |
$url = get_page_link( $pages[0]['id'] ); | |
} | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment