Forums

[resolved] Query tag and post per page (4 posts)

  1. jumust
    Member
    Posted 4 months ago #

    Hi I have this function

    <?php
    	$the_query = new WP_Query( array( 'tag__in' => array( 32, 33, 34 ) ), 'posts_per_page' => 3 );
    	while ( $the_query->have_posts() ) : $the_query->the_post();
    ?>

    what's wrong, if I use only tag_in it works. Can I combine tag_in and post_per_page?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 months ago #

    <?php
    $args = array(
    	 'tag__in' => array( 32, 33, 34 ),
    	 'posts_per_page' => 3
    );
    $my_query = new WP_Query( $args );
    while ( $my_query->have_posts() ) : $my_query->the_post();
    ?>
  3. jumust
    Member
    Posted 4 months ago #

    Thanks it works but it gets the 3 most recent posts (whatever of those 3 tags) and not ONE POST FOR EACH TAG. What should I add?

  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 months ago #

    Then you need 3 loops - 1 for each tag.

Reply

You must log in to post.

About this Topic