Find All Pages Using a Template in WordPress

Find All Pages Using a Template in WordPress

Posted by Rainey

Super short post on with a super powerful WordPress snippet.  I ran into a situation where I needed to find pages that are using a specific page template in WordPress and here is what I found.

$pages = get_pages(array(
	'meta_key' => '_wp_page_template',
	'meta_value' => 'page-product.php'
));
foreach($pages as $page){
	echo $page->post_title.'<br />';
}

-> Found here.

 

Taking this one step farther, maybe I would like to generate links for these:

$pages = get_pages(array(
	'meta_key' =&gt; '_wp_page_template',
	'meta_value' =&gt; 'page-product.php'
));
foreach($pages as $page){
	echo '<a href="'.$page->guid'">'.$page->post_title.'</a>';
}

Like what you are reading? Subscribe to receive monthly tips & updates!

A Monthly Roundup of Articles and a Sweet Deal

Get the latest tips, tricks, tutorials and freebies in your inbox once a monthly.

Join our growing community of front-end web developers and designers. We are constantly publishing new industry tips, tricks and tutorials to help you take your game to the next level. We are also going to include a freebie or deal on something cool each month. Enter your email below and you will only receive this email once a month, nothing else.

Subscribe to our mailing list

* indicates required


    Today in Web Design - Snippets, Tutorials, WordPress
    Tagged | ,