[Support request] Specific posts from category not displaying on page

Home Forums Support [Support request] Specific posts from category not displaying on page

Home Forums Support Specific posts from category not displaying on page

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1114682
    Neil

    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>
    #1114782
    Leo
    Staff
    Customer Support

    Hi there,

    Not sure if I understand.

    Is this for the posts page or a static page?

    #1115011
    Neil

    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.

    #1115383
    Tom
    Lead Developer
    Lead Developer

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

    Just to confirm, does this category have published posts?

    #1115529
    Neil

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

    The category does have published posts.

    Thanks

    #1115613
    Tom
    Lead Developer
    Lead Developer

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

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.