Site logo

Archived topic

Specific posts from category not displaying on page

5 replies · Started by Neil on December 26, 2019

Viewing posts 1–6 of 6

I've created this hook in the elements section after_main_content with priority 22.

The aim is to use a page as a hub and display only posts from a specific category.

Not sure what is wrong here but none of my posts a specific category are displaying.

Below is the code I put in the element hook.

<div class="generate-columns-container">	
<?php
	$args = array(
		'post_type' => 'post',
		'cat'=>39,
		'posts_per_page' => -1,
		'post_status'     => 'publish',
		'order' => 'ASC'
);
$query = new WP_Query( $args );
    if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
    if (has_post_thumbnail()) { ?>
	<article <?php $postid = get_the_ID(); ?> class="hub-grid tablet-grid-50 mobile-grid-100 grid-parent grid-33 no-featured-image-padding" itemtype="https://schema.org/CreativeWork" itemscope="">
		<div class="inside-article design-article">	
	<header class="entry-header">
		<a href="<?php get_permalink( $postid ); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail(); ?></a>
 	</header>	
	<div class="entry-summary" itemprop="text">
	<h2 class="entry-title" itemprop="headline"><a href="<?php the_permalink($postid); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
	<?php the_excerpt(); ?>
		
	<div>			
		</div>
	</article>																																						 <?php
    } 
	endwhile;endif;?>
</div>

Hi there,

Not sure if I understand.

Is this for the posts page or a static page?

This is a static page that is being used to loop all posts from a specific category.

I've added the above hook to do this but it returns nothing.

Can you try adding quotations around the category ID?: '39'

Just to confirm, does this category have published posts?

I did that and I've also tried category_name. None of them work.

The category does have published posts.

Thanks

Do those posts have a featured image? Your code is saying to only output the posts if a featured image exists.

This archived topic is closed to new replies.