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
- WordPress duplicating posts from single loop
- Use Custom Field to Display Post Loop
- WP_Query: include custom post type only with specific meta value
- WP_Query orderby modified to include custom meta changes
- WordPress custom loop filter by meta_key and value with serialize data
- Returning a list of custom post types excluding those without a specific meta_value
- Two near-identical custom field types – one works, the other doesn’t . What can cause this?
- Retrieve value of a category’s custom field
- wp_query check if integer exists in custom field’s array
- How can I dynamically add a post to a custom post type which uses a custom field?
- How can I get the number of custom post type posts that have a specific attachment image set?
- Bulk Update Custom Fields for Custom Post Types
- 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
- Including metaboxes from custom post types in global search — continued
- ACF From & To Date Validations
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- How to render a custom post type template with custom fields using shortcode
- Get Posts by multiple custom fields is not working
- Query Custom Post Type Taxonomy term with multiple parameters
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- First custom field value (out of several) displayed twice after query
- Multiple Frontend Filters Using Advanced Custom Fields
- Integrate Custom Post Type Events into Calendar
- Possible to filter custom post type with multiple meta data?
- Displaying custom field according to date
- WebP Fallback for Inline Background Image in Style Attribute
- Redirect to another page using contact form 7? [closed]
- Why is my WP Query not returning first result’s post meta?
- DIsplaying URL of custom field in last post of certain taxonomy && post type
- Recoverable Fatal Error – Object of class WP_Post could not be converted to string
- How to get a custom type post data when it has a connection with another custom type post?
- WP Query ‘posts_per_page’
- Display post from a date range from custom field
- post_per_page ignored in WP_Query
- List of users that clicked a ‘Join’ button at single post
- How to get specific post meta by title or id
- Getting a custom post’s custom field based on another custom post’s custom field select
- How to inherit field value from parent post into in child / sub post
- WP_Query orderby not work with meta_key
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- 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?
- How do I replace the post title with a custom field?
- Display custom post type for specific user
- Sum and count of custom field values
- Custom Post type loop with ACF not displaying properly
- Custom post types, disable fields
- meta query not retrieving posts
- Get A Custom Field From A Custom Taxonomy Of A Custom Post Type [closed]
- 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
- Excerpt length: get first paragraph
- How do I list a custom field and custom taxonomies for each result in a loop?
- WP query_posts group by meta field related
- date_query empty results with custom post type
- 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
- Orderby meta_key/meta_value not displaying anything, am I overlooking anything?
- Custom Form / Search with Custom Post Type Data
- WP Query from two Custom Post type fields as statement
- 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
- Using ACF values in nested WP queries for CPT with date values in the past
- 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
- Display Custom Field or Custom Taxonomy in front page /post/product
- How to access repeater field of a custom field?
- How can I fetch all the dates from custom fields from various different custom post types and show / list them at one place in ascending order?
- 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
- Sort custom post archives by a meta value from a different custom post type?
- filter using custom fields
- Custom post types – meta_query: search lesson which starts sooner
- Query a custom taxonomy in a function to create an csv file
- 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