Skip to content

Instantly share code, notes, and snippets.

@AlexWebLab
Created March 13, 2018 10:05
Show Gist options
  • Save AlexWebLab/a8f29fb5a6cd5f3ce7c5a538f679370f to your computer and use it in GitHub Desktop.
Save AlexWebLab/a8f29fb5a6cd5f3ce7c5a538f679370f to your computer and use it in GitHub Desktop.
Get page ID by template name in WordPress
<?php
$args = [
'post_type' => 'page',
'fields' => 'ids',
'nopaging' => true,
'meta_key' => '_wp_page_template',
'meta_value' => 'page-special.php'
];
$pages = get_posts( $args );
foreach ( $pages as $page )
echo $page . '</br>';
@haque
Copy link

haque commented Dec 10, 2020

Thanks for this code.

@AlexWebLab
Copy link
Author

Thanks for this code.

You’re welcome!

@rainb3rry
Copy link

good one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment