I’m working on a WordPress site and facing a weird issue. I have a custom template that shows a specific post type, and everything works fine when I’m logged into the admin area. But when I log out and view the same page as a regular visitor, no posts show up at all.
The posts are definitely published and set to public visibility. They appear correctly in other parts of the site. Here’s my template code:
<?php /*
Template Name: Courses Display
*/ ?>
<?php get_header(); ?>
<div class="content-wrapper">
<div class="container">
<h1><?php the_title(); ?></h1>
<div class="course-grid">
<?php
$course_query = new WP_Query(array(
'post_type' => 'course_listings',
'post_status' => 'publish',
'meta_key' => 'course_priority',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'posts_per_page' => -1
));
if ($course_query->have_posts()) {
while ($course_query->have_posts()) {
$course_query->the_post();
$featured_image = get_post_meta(get_the_ID(), 'course_thumbnail', true);
?>
<div class="course-item">
<?php if ($featured_image) { ?>
<img src="<?php echo $featured_image; ?>" alt="Course Image" />
<?php } ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>" class="read-more">Learn More</a>
</div>
<?php
}
} else {
echo '<p>No courses available.</p>';
}
wp_reset_postdata();
?>
</div>
</div>
</div>
<?php get_footer(); ?>
I’ve tried rewriting the query multiple times and even tested with different post types, but the same thing happens. The posts only show when I’m logged in as admin. Any ideas what could cause this behavior?