try this wich first stack all posts with same times
$tabEvent = [];
foreach ( $rand_posts as $post ) {
setup_postdata( $post );
$start_time = get_field("start_time");
$end_time = get_field("end_time");
$index = "$start_time|$end_time";
// store all the posts with same times
if (!isset($tabEvent[$index])) {
$tabEvent[$index] = [];
}
$tabEvent[$index][] = $post;
}
foreach ($tabEvent as $index => $listeEvent ) {
echo "<h2>$index<h2/>";
foreach ($listeEvent as $post) {
// all posts with the same times
echo "<h3>{$post->post_title}<h3/>";
}
}
Related Posts:
- Filtering a WP_Query meta_query by numeric values isn’t working
- Display posts if a custom field value is equal to another custom field value
- Custom Post type and Custom Field WP_Query
- WP_Query order by custom field, then randomly order some of results
- Query custom post type with ACF Date
- Stuck in Order by more then one
- Query Multiple Custom Posts by Custom Fields
- Order Custom Post Type by Custom Field Value
- Query based on custom fields start and end date
- Create if else for post types in WP_Query ‘post__in’ values
- Filter posts by their related field’s custom field
- Display ACF object field data using Elementor Custom Query
- Multiple orderby values in WP_Query
- Search multiple custom fields by using meta_query
- how to filter by last name for custom post
- Automatically fill custom field value on post publish/update
- Filtering a WP Query result
- Display Custom Post Type Fields
- How to sort a table of custom posts by column containing custom field
- Using new WP_Query in shortcode in a custom field causes the main post content to not display
- WordPress query by multiple Custom fields and order by date
- WP Query group/order by category name
- Query current and future events, ordered by begin date
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- Query Custom Post Types by date (custom field) range
- wp_query to find posts by year and month
- How to dynamically attach pictures to a carousel
- Remove duplicated values from a loop
- Display multiple custom post types and sort them chronological by one of their fields
- Including Custom Meta with posts_where query
- WP_Query: include custom post type only with specific meta value
- WordPress custom loop filter by meta_key and value with serialize data
- How can I dynamically add a post to a custom post type which uses a custom field?
- Problem querying Custom post type by custom fields
- Orderby CPT custom fields not working
- Troubles with acf/save_post and WP_Query
- Meta Query Not Returning Output Despite Having Matching Values
- ACF From & To Date Validations
- First custom field value (out of several) displayed twice after query
- Multiple Frontend Filters Using Advanced Custom Fields
- Possible to filter custom post type with multiple meta data?
- Displaying custom field according to date
- How to get specific post meta by title or id
- How to inherit field value from parent post into in child / sub post
- Custome fields not displayed
- posttype and custom fields on multisite
- How do I get_the_postID() for a custom post that uses ACF repeater field?
- meta query not retrieving posts
- Get posts by category name
- Using WP meta query to show custom post types by a start and finish date
- How to properly use Categories with Custom Post Types
- Cache issue with WP_Query and custom field filtering
- How do I list a custom field and custom taxonomies for each result in a loop?
- Having a repeating custom field in admin custom post type, what I’d go better with, for DB’s sake? ACF repeater or query a different post type?
- ACF – Retrieve custom taxonomy from a relationship field
- Alike Shortcode using in Custom Shortcode
- Sort custom posts by date and then by taxonomy
- Query custom post type that has a serialized relational advanced custom field value
- WP Admin Dropdown List Filter for custom (ACF) field on custom post type(s)
- WP_Query get always custom post_type for first
- Sort custom post column by generated value?
- How can I query and sort custom-post type using WP_Query
- Query custom post type and custom field by URL parameters
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Query a Custom Post Type using SELECT that has ACF fields to compare dates
- meta query multiple values for the same key
- Custom post types – meta_query: search lesson which starts sooner
- Wrapping an unknown amount of posts inside separate HTML Containers during WP_Query loop
- Post Filtered by Custom Field Value
- Show specific posts with WP_Query using ACF Post object
- Filter custom WP_Query by first letter of a custom field – hopefully using Search and Filter Pro?
- sorting in wp query based on custom field value
- Query posts based on user preferences
- Meta_Query refuses to return results
- Linking posts together with Advanced Custom Fields “both ways”
- Custom Field as Custom Post type element class
- Why get_posts() returns empty array while I am trying to get posts from some specific taxonomies and work properly with others?
- Automatically convert standard posts with custom fields to custom post types
- WordPress query in which condition uses custom field
- WordPress loop add heading before first of type
- How to make a shortcode for my WP_Query Loop? [duplicate]
- Error in WP Query. If variable is empty it is displaying previous post value
- Query events post type after current date and timezone
- This wp_query will not return any posts and only seems to work with post_status inherit?
- Get month and day from a Date Picker custom field
- How to stop wp_query searching pages as well as the specified CPT
- How to query posts by meta keys AND under specific category?
- Query posts by a type and another type only if post is in specific category
- Setting a custom $query->query_vars[‘meta_key’] breaks the WordPress menu
- WP_Query and two custom fields returns no posts
- Storing/querying custom date data
- Custom Post-type not returning the right child_of
- shortcode for recent custom type post
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts
- How to show all posts of specific custom post type with their custom fields values?
- querying to custom field over ACF REST API
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?
- WordPress custom field sorting, weird behavior: the latest post is at the end
- Sort CPT by taxonomy AND THEN by custom field
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?