Hello,
I'm using get_pages() and then have a foreach to create a custum menu. Is it here possible to exclude pages that are using a specified template? or in the loop see if the page template is the one i want to exclude and then don't print it?
Hello,
I'm using get_pages() and then have a foreach to create a custum menu. Is it here possible to exclude pages that are using a specified template? or in the loop see if the page template is the one i want to exclude and then don't print it?
Use this code in your foreach loop
<?php
$template_file = get_post_meta($YourMenuPageId->ID, '_wp_page_template', true);
if( $template_file == 'page-dontwant.php' ) continue;
?>don't forget change
$YourMenuPageId->ID and 'page-dontwant.php'
or use this args for get_pages($args) to include certain template file
'meta_key' => '_wp_page_template',
'meta_value' => 'page-onlythispages.php'Thank you very much! I've googled this for hours and you solved it in like 5 minutes.
Sorry to reply to an old post.... but do you know how to do the opposite of this? (ONLY display from a specific template)
This topic has been closed to new replies.