Last active
November 16, 2016 22:49
-
-
Save sirtimid/f078ece786be3eefed8e135c0b9667b7 to your computer and use it in GitHub Desktop.
Get a wordpress page URL by template name
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 | |
if(!function_exists('get_url_by_template')){ | |
function get_url_by_template($tmpl){ | |
$pages = query_posts(array( | |
'post_type' =>'page', | |
'meta_key' =>'_wp_page_template', | |
'meta_value'=> $tmpl | |
)); | |
$url = null; | |
if(isset($pages[0])) { | |
$url = get_page_link($pages[0]->ID); | |
} | |
wp_reset_query(); | |
return $url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment