Exclude from wp_list_pages by template

I would like content creators to be able to select a page template when editing the page that indicates the page should not be included in the sitemap

This seems a bit awkward to me. I would suggest instead to add a meta box that enables content creators to toggle an “include in sitemap” setting for each page. That said, the mechanism for excluding those pages from wp_list_pages would be the same, as the selected template is also stored in post meta data under the key _wp_page_template.

The first step is to get all of the page IDs that satisfy our meta query, whether that be checking for a page template or a flag you set in your meta box handler to denote that page is to be excluded from the sitemap. We also set the fields argument so the returned posts contains only an array of IDs. This will save memory versus querying entire page objects.

$args = array(
    'fields' => 'ids',
    'post_type' => 'page',
    'posts_per_page' => -1,
    'meta_query' => array(
            'key' => '_hide_from_sitemap',
            'compare' => 'EXISTS',
$pages_to_exclude = new WP_Query( $args );

After this is run, $pages_to_exclude->posts will be an array of page IDs that you can pass directly as the exclude argument of wp_list_pages.