If you want to get the ID of a page on a specific template, you can use the following code below.

If the Page Template is right after Main Theme.

<?php
// Formula
$get_template_data = get_pages(array('meta_key' => '_wp_page_template', 'meta_value' => 'filename.php'));

// Example
$get_template_data = get_pages(array('meta_key' => '_wp_page_template', 'meta_value' => 'page-sample.php'));
$get_template_id = $get_template_data[0]->ID;
echo $get_template_id;
?>

If the Page Template is inside the folder of the Main Theme.

<?php
// Formula
$get_template_data = get_pages(array('meta_key' => '_wp_page_template', 'meta_value' => 'foldername/filename.php'));

// Example
$get_template_data = get_pages(array('meta_key' => '_wp_page_template', 'meta_value' => 'page-templates/page-sample.php'));
$get_template_id = $get_template_data[0]->ID;
echo $get_template_id;
?>
ADVERTISEMENT

Leave a Comment

Subscribe to the Newsletter

Subscribe to get my latest content by email. I won't send you spam. Unsubscribe at any time.

Newsletter
ADVERTISEMENT

Similar Searches:

  • Get page id by template