Last active
October 8, 2020 22:10
-
-
Save iamgaby7521/b285cd00328d607f56bba0be239cd20c to your computer and use it in GitHub Desktop.
Get page link by template (only gets the first page from the array)
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_page_link() { | |
$pages = get_pages( array( | |
'meta_key' => '_wp_page_template', | |
'meta_value' => 'templates/page-template_name.php' | |
) ); | |
if ( $pages ) { | |
$link = esc_url( get_permalink( $pages[0]->ID ) ); | |
} else { | |
$link = ''; | |
} | |
return $link; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working, thanks very much. You better rename get_page_link() with another name (i.e get_page_link_by()) for avoiding WP core conflicts in my tests.