Support » Themes and Templates » Exclude Pages by Page Template?

  • My blog template displays all pages in the top, under my title, and such. I would like to exclude all pages of a template called Custom Works. How do I do it? I already created the template PHP file, and it prints the content just fine.

    I checked the wp_list_pages function, but it only excludes pages by ID.

    Better yet, if I can make the Custom Works template pages unlisted (don’t appear anywhere unless you link them), that would also work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can use this bit of code/sql query to ‘discover’ which Pages are assigned a specific template, and exclude those from your Page list (change value of $template to the filename of the Page template you need to match):

    $template = 'custom-works.php';

    $Pages = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = '$template'");
    foreach($Pages as $Page) {
    $exclude_Pages .= $Page . ',';


    Brilliant, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude Pages by Page Template?’ is closed to new replies.