Forums

get_pages() where template (6 posts)

  1. gubbfett
    Member
    Posted 1 year ago #

    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?

  2. julio5
    Member
    Posted 1 year ago #

    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;
    ?>
  3. julio5
    Member
    Posted 1 year ago #

    don't forget change
    $YourMenuPageId->ID and 'page-dontwant.php'

  4. julio5
    Member
    Posted 1 year ago #

    or use this args for get_pages($args) to include certain template file

    'meta_key' => '_wp_page_template',
    'meta_value' => 'page-onlythispages.php'
  5. gubbfett
    Member
    Posted 1 year ago #

    Thank you very much! I've googled this for hours and you solved it in like 5 minutes.

  6. apax27
    Member
    Posted 3 months ago #

    Sorry to reply to an old post.... but do you know how to do the opposite of this? (ONLY display from a specific template)

Topic Closed

This topic has been closed to new replies.

About this Topic