Support

Account

Home Forums ACF PRO Show 4 page titles based on next dates Reply To: Show 4 page titles based on next dates

  • For doing custom queries in WP you will want to learn WP_Query https://codex.wordpress.org/Class_Reference/WP_Query.

    ACF saves dates as YYYYMMDD

    Then you do a WP_Query using the field name of your ACF field in a meta_query

    The query below uses a new feature in WP that’s not in the codex yet and is explained here https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/

    
    // if this isn't in a template that already have the global $post
    // available you may need to do
    // global $post;
    $today = date('Ymd');
    $args = array(
        'post_type' => 'page', // or your post type
        'posts_per_page' => 4, // the number of posts you want to show
        'meta_query' => array(
            'date_clause' => array(
                'key' => 'name_of_date_field',
                'value' => $today,
                'compare' => '>='
            ),
        ),
        'order_by' => array(
            'date_clause' => 'ASC',
            'title' => 'ASC',
        ),
    );
    $query = new WP_Query($args);
    if ($query->have_posts()) {
        $query->the_post();
        // loop to show what was returned in query
    }
    wp_reset_postdata();
    

    For more information on queries and loops see the codex page I linked to above.