• Resolved Lalit Jindal

    (@lalitjindal)


    Hi.

    I’m trying to build an “Advanced custom loop” with Kadence plugin to show future games. But since the future games are not actually published, kadence is not picking those posts. Is there a way around that?

    The page I need help with: [log in to see the link]

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

    (@lalitjindal)

    Chatgpt says this should work. But it doesn’t. It shows nothing.

    //

    add_filter( ‘kadence_blocks_pro_query_loop_query_vars’, function( $query, $ql_query_meta, $ql_id ) {

    if ( $ql_id == 123 ) {
    $query[‘post_type’] = ‘sp_event’; // Ensure it’s querying SportsPress events
    $query[‘post_status’] = array( ‘publish’, ‘future’ ); // Include scheduled events
    $query[‘meta_query’] = array(
    array(
    ‘key’ => ‘_sp_date’, // Adjust if necessary
    ‘value’ => date(‘Y-m-d H:i:s’),
    ‘compare’ => ‘>=’,
    ‘type’ => ‘DATETIME’,
    )
    );
    $query[‘orderby’] = ‘meta_value’;
    $query[‘meta_key’] = ‘_sp_date’;
    $query[‘order’] = ‘ASC’;
    }

    return $query;
    }, 10, 3 );

    //

    Thread Starter Lalit Jindal

    (@lalitjindal)

    This works(change $ql_id):

    add_filter( ‘kadence_blocks_pro_query_loop_query_vars’, function( $query, $ql_query_meta, $ql_id ) {

    if ( $ql_id == 123 ) {
    $query[‘post_type’] = ‘sp_event’;
    $query[‘post_status’] = array( ‘publish’, ‘future’ ); // Include scheduled games

      $query['date_query'] = array(
         array(
            'after'     => date('Y-m-d H:i:s'), // Only show future games
            'inclusive' => true,
         ),
      );
    
      $query['orderby'] = 'post_date'; // Order by scheduled event date
      $query['order'] = 'ASC'; // Show earliest upcoming games first

    }

    return $query;
    }, 10, 3 );

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Kadence loop for future events’ is closed to new replies.