There’s no need to split the array, you can just close the first div once you’ve counted up to four elements of the array.
$args = array(
'post_type' => 'event',
'meta_key' => 'date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'posts_per_page' => 8,
'meta_query' => array(
'key' => 'date',
'value' => date('Y-m-d',strtotime("today")),
'compare' => '>=',
'type' => 'DATE'
),
);
$events = new WP_Query( $args );
$count = 1;
if ( $events->have_posts() ) : ?>
<div class="column-1">
<?php while ( $events->have_posts() ) : $events->the_post();
// YOUR CONTENT
if ( $count == 4 ) { ?>
</div>
<div class="column-2">
<?php }
$count++;
endwhile;
wp_reset_postdata();
endif;
?>
</div>
Related Posts:
- Can an array be used as a meta_query value?
- How do I dynamically generate args for wp_query?
- How to use $query->set with post__in?
- Exclude posts based on meta value
- Getting posts to exclude from array
- Get all posts as an array ID => Name
- extract serialized array to use for wp-query
- array_rand not working correctly?
- Order a WP_Query by meta value where the value is an array
- Using multiple variables to assign categories to an array
- Sending simple variable on single page to WP JSON
- in_array not working on dev server but works on localhost
- Combine multiple queries, array_unique returns nothing
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- Reprinting tags with all attributes
- Dynamic content based on a URL parameter
- Display a specific category of products in shop page and disable code for specific actions
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- PHP Array Returning [object Object]. Tried existing answers results with no luck
- foreach loop still echoes array
- WordPress, AJAX and pre_get_posts using conditional tags
- Get users that likes the post
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- Custom query, checking values of multiple meta keys
- auto-populating custom nav with all items from custom post type
- Checking array against author id in loop
- inserting a post from an extern php file but post content doesn’t show on wp site
- Remove echo from shortcode
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- WordPress theme options error
- Redirect to another page using contact form 7? [closed]
- Security for data obtained from the database
- Alter required message using comment form api
- Fatal error: Call to a member function query() on a non-object
- Get posts from multiple post type
- Advanced Custom Fields – display label and value only if value entered
- Is it possible to retrieve all posts with a certain value for metadata?
- meaning of (array)function()
- How to get all author posts outside of author templates
- WP_Query fails despite having 1 post
- Grouping posts by a custom meta value
- Create a Blog Template Page
- unable to use ‘new WP_Query’ in AJAX call
- wp_force_remove_style’ not found
- wp_query get the 2nd post
- Exclude posts with specific metadata from search?
- How to get post ID in a Page?
- How to fix this warning:call_user_func_array() expects exactly 2 parameters, 1 given in D:\wamp\www\…….\wp-includes\class-wp-hook.php on line 286
- How can I access string value in an array?
- How to use if statement in an array? [closed]
- Display an image if odd number of posts in grid
- How to array only one key from another array
- How to retrieve the data from the sever and displaying it in a page?
- Filtering a function’ output for a new continued function
- How do I turn these values from MYSQL into an array
- How to add div blocks after certain set of post
- Get html data with javascript to php array and store to wordpress database
- How to overwrite orderby with add_query_var
- How do I create a numbered list with PHP? [closed]
- Why is an array created in a function hooked to customize register populated when customizer is loaded but not when the front-end is loaded?
- How to use array in function to get only value I want
- Error while setting role
- Get categories names as an array to use it in theme settings
- Why doesn’t PhotoSmash plugin play well with wp_query?
- get_the_ID() in the footer returns wrong value
- Trouble inputting variable into WP query
- How to get the last category name of a child category?
- the_posts_pagination() not working in wpquery
- How to say if meta_value is greater than 0 in an array?
- How to use two meta_compare in an array?
- Warning: in_array() null given in PHP function
- How to override url params with rewrite rules vars?
- WP_Query: getting posts where custom field exists
- Foreach loop inside an array_merge
- How to show meta value code HTML after x paragraph
- Form search query – displaying ACF “Post Object” field as results
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- Convert a string into a decimal number for use in query
- How to display SQL query that ran in WC_Order_Query?
- get_the_ID() doesnt work
- Loop over Array and get the distinct ids
- Array to string conversion on array_map
- Store metakey value as an array
- Increment paged on WP_Query
- Target post_date_gmt if it’s empty or not set
- How to access or parse key/values that have “string”
- If Array Values Match Another Array’s Values, Then
- Hide posts if user is added to it WP_query
- Remove empty terms from array, sort alphabetically, update back to repeating field
- WordPress loop by meta key that is an array? and how loop multiple arrays
- Only show first image in foreach loop
- Conditional multidimensional arrays and array_map
- Custom route and query
- change the default order of posts only for specific categories