Get Pages using custom template

I’m trying to create a custom rewrite rule, but to achieve this I need the page slug and ID for a page that uses a specific template to put into the rewrite rule.

In a normal WP theme I would use get_pages() with the template file php name, such as (template-custom.php) but this doesn’t seem to return anything in this case when using the blade template. What do I need to put as the meta value to find this page?

$args = [
        'post_type' => 'page',
        'meta_key' => '_wp_page_template',
        'meta_value' => 'template-custom.blade.php'
  ];

$pages = get_pages($args);

Hey @chrisrhymes - try adding ‘views/’ to the template name:

 $args = [
        'post_type' => 'page',
        'meta_key' => '_wp_page_template',
        'meta_value' => 'views/template-custom.blade.php'
  ];

$pages = get_pages($args);
2 Likes