I'm trying to create a custom page for a WordPress theme, which is a child theme of the Twenty Twenty theme. I'm simply trying to use WP_Query()
to filter out posts so that it only displays posts with the category slug locations
, however it produces two issues.
1.) It does not filter out the posts, and shows posts in any category.
2.) The error Notice:
Undefined offset: 9 in /Users/g/Documents/MAMP/childtheme/wp-includes/class-wp-query.php on line 3271 repeats over and over with increasing offsets numbers until the browser crashes.
$q = new WP_Query( array('category_name' => 'locations' ));
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
the_post();
get_template_part( 'template-parts/content', get_post_type() );
}
}
I have a feeling it's something silly, but I have been at it for a few hours and haven't found the issue. Any help would be appreciated.
the_post();
to map to your custom loop$q
, like$q->the_post();
and the filter should run.