I am trying to get latest from specific categories (3 posts), but the code does not seem working. Instead of displaying posts from the mentioned categories, it is displaying posts from the first category.
Here is my code:
<?php do_action( 'hitmag_before_content' ); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<h1>Latest News</h1>
<?php do_action( 'hitmag_before_blog_posts' ); ?>
<?php $args = array(
'post_type' => 'post' ,
'orderby' => 'date' ,
'order' => 'DESC' ,
'posts_per_page' => 3,
'category' => '30','33','1',
'paged' => get_query_var('paged'),
'post_parent' => $parent
); ?>
<?php query_posts($args); ?>
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
$archive_content_layout = get_option( 'archive_content_layout', 'th-grid-2' );
echo '<div class="posts-wrap ' . esc_attr( $archive_content_layout ) . '">';
/* Start the Loop */
while ( have_posts() ) : the_post();
/*
* 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( 'template-parts/content', get_post_format() );
endwhile;
echo '</div><!-- .posts-wrap -->';
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
<?php do_action( 'hitmag_after_blog_posts' ); ?>
</main><!-- #main -->
</div><!-- #primary -->
I am trying to get latest from specific categories (3 posts), but the code does not seem working. Instead of displaying posts from the mentioned categories, it is displaying posts from the first category.
Here is my code:
<?php do_action( 'hitmag_before_content' ); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<h1>Latest News</h1>
<?php do_action( 'hitmag_before_blog_posts' ); ?>
<?php $args = array(
'post_type' => 'post' ,
'orderby' => 'date' ,
'order' => 'DESC' ,
'posts_per_page' => 3,
'category' => '30','33','1',
'paged' => get_query_var('paged'),
'post_parent' => $parent
); ?>
<?php query_posts($args); ?>
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) : ?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
$archive_content_layout = get_option( 'archive_content_layout', 'th-grid-2' );
echo '<div class="posts-wrap ' . esc_attr( $archive_content_layout ) . '">';
/* Start the Loop */
while ( have_posts() ) : the_post();
/*
* 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( 'template-parts/content', get_post_format() );
endwhile;
echo '</div><!-- .posts-wrap -->';
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
<?php do_action( 'hitmag_after_blog_posts' ); ?>
</main><!-- #main -->
</div><!-- #primary -->
Share
Improve this question
asked Aug 12, 2020 at 16:04
Imtango30Imtango30
1425 bronze badges
2 Answers
Reset to default 0The short answer is that the value for category
should be an array of IDs.
The longer answer is that it is rarely appropriate to use query_posts
at all.
Use category__in instead of category.
So just replace:
'category' => '30','33','1',
with
'category__in' => array( '30','33','1'),