I am having difficulties excluding a specific page from my main index loop in my child theme.
I have the following function found in functions.php that modifies my index.php loop so that it displays pages instead of posts:
add_action( 'pre_get_posts', 'pages_loop_on_index' );
function pages_loop_on_index( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'page' ) );
$query->set( 'posts_per_page', -1 );
}
}
So far, so good.
I want to make it so that the loop ignores page ID 34 but I can't get this part to work.
I've tried using :
$query->set( 'category__not_in', '34' );
Still shows up.
I've tried :
$query->set( 'exclude', '34' );
But the page still shows up.
What am I doing wrong?
Here's the code for index.php:
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php boardwalk_paging_nav(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</main><!-- #main -->
</div>