Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:11:37+00:00 2026-06-14T20:11:37+00:00

I have a loop through my custom post types. I want to select 8

  • 0

I have a loop through my custom post types.

I want to select 8 posts only, and print out the output into 2 columns, 4 posts each. I’m not really sure how to approach this. So far I have:

<?php
            $args = array( 'post_type' => 'hh_event', 'posts_per_page' => 8 );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post();

                echo '<div class="entry-date">';
                $event_date = get_post_meta($post->ID, 'event_date', true); 
                echo date('M j',strtotime($event_date));
                echo '</div>';
                the_title();
                echo '<div class="entry-content">';
                the_content();
                echo '</div>';

            endwhile;
        ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:11:38+00:00Added an answer on June 14, 2026 at 8:11 pm

    A simple solution would be to have your content stored in an array like so:

    <?php
    $args = array( 'post_type' => 'hh_event', 'posts_per_page' => 8 );
    $loop = new WP_Query( $args );
    
    $columns = array( '', '' );
    $content = '';
    $i = 0;
    global $post;
    
    while ( $loop->have_posts() ) : $loop->the_post();
        $content = '<div class="entry-date">';
        $event_date = get_post_meta($post->ID, 'event_date', true); 
        $content .= date('M j',strtotime($event_date));
        $content .= '</div>';
        $content .= get_the_title();
        $content .= '<div class="entry-content">';
        $content .= apply_filters( 'the_content', $post->post_content );
        $content .= '</div>';
    
        $columns[ ($i % 2) ] .= $content;
        $i ++;
    endwhile;
    
    echo '<div class="column-left">' . $columns[0] . '</div><div class="column-right">' . $columns[1] . '</div>';
    
    ?>
    

    So basically you have an array containing two empty strings. You then assign the content of each column to a variable named $content. You then append the value of that variable to the proper part of the $columns variable and increment the counter $i.

    Then just echo the contents of each column to a proper wrapping <div> element, or however you are going to separate those into two columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below but want to only loop through lines in #lines which
I have a custom list with name,age and grade .I want to loop through
How to loop through a select statement results to have a formatted text? for
I have a list that I want to loop through (for trimtemp in trim)
I have a listbox and I want to loop through each of the items
So I'm using a custom loop to output a custom post type on some
I have a controller method that throws a custom exception if a loop through
I have various custom component instances in my flex app. I want to loop
Basically I have a custom post type setup called Parts with over 5,000 posts
I have a set of categories I want to loop through, and set a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.