• I am looking to do a wp_query for all events that already have finished, what field attribute do i check against today to see if the event is already over, is it different for recurring events?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter shuangmiles

    (@shuangmiles)

    I tried to do it like this but got no results
    
    
    
    ?// WP_Query arguments to find events that have ended
    
    ? ? $query_args = array(
    
    ? ? ? ? 'post_type' => 'event', // Custom post type name
    
    ? ? ? ? 'posts_per_page' => -1, // Retrieve all events, or specify a specific number
    
    ? ? ? ? 'meta_query' => array(
    
    ? ? ? ? ? ? array(
    
    ? ? ? ? ? ? ? ? 'key' => 'event_end_date', // Name of the custom field
    
    ? ? ? ? ? ? ? ? 'value' => $current_date, // Compare against today's date
    
    ? ? ? ? ? ? ? ? 'compare' => '<', // Look for dates before today
    
    ? ? ? ? ? ? ? ? 'type' => 'DATE', // Specify the data type for comparison
    
    ? ? ? ? ? ? ),
    
    ? ? ? ? ),
    
    ? ? ? ? 'orderby' => 'meta_value', // Order by the event_end_date
    
    ? ? ? ? 'order' => 'DESC', // Order descending, so the most recent end date is first
    
    ? ? );
    
    ? ? $query = new WP_Query( $query_args );
    Thread Starter shuangmiles

    (@shuangmiles)

    I saw that I can do something like but how can I instead of outputting html elements to output the array of items i want to access like the event post id for instance and loop through each

    if ( class_exists(‘EM_Events’) ) {

            echo EM_Events::output( array(‘limit’ => -1,’orderby’ => ‘name’, ‘scope’ => ‘past’, array) );

        }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to go about querying all events that have already ended’ is closed to new replies.