Get page template ID – WordPress

Get the page ID with a page template assigned to it

$sql = "select post_id from $wpdb->postmeta where meta_key like '_wp_page_template' and meta_value = 'template-products.php'";
$result = $wpdb->get_results( $sql );
foreach ( $result as $value ) {
    $page_id = $value->post_id;
}
wp_reset_query();

Leave a Reply

Your email address will not be published. Required fields are marked *