Support

Account

Home Forums Front-end Issues Orderby Date Picker in a Group

Solved

Orderby Date Picker in a Group

  • Hi All,

    Sorry if this is redundant. I searched through everything a ton but can’t seem to figure it out.

    I’ve got a group that has a start and end date. I’d like to order by the start date. The group’s name is showit_event_dates and the start date is start_event.

    I’ve tried the way that ACF uses:

        $args = array (
          'post_type'       => 'showit_events',
          'posts_per_page'  => $num_posts,
          'orderby'         => 'meta_value',
          'meta_key'        => 'start_event',
          'order'           => 'DESC'
        );

    And by also using the meta_query instead of meta_key:

        $args = array (
          'post_type'       => 'showit_events',
          'posts_per_page'  => $num_posts,
          'orderby'         => 'meta_value',
          'meta_query'     => array(
    			array(
    				'key'       => 'start_event',
    				'value'     => date('F j'),
    				'type'      => 'DATE',
    				'compare'   => '=',
    			)
            ),
          'order'           => 'DESC'
        );

    Neither renders anything. I’m guessing because the dates in the group are treated as arrays???

    Any help would be amazing. I’ll attach my date settings.

  • Okay…thanks to a friend who sent me this link: https://stuartfarish.com/advanced-custom-fields-sort-by-field-group-sub-field/

    All you have to do is add the field name of the group to the beginning of the subfield. The name of my group is showit_event_dates. So, the code should look something like this:

    $args = array (
          'post_type'       => 'showit_events',
          'posts_per_page'  => $num_posts,
          'orderby'         => 'meta_value',
          'meta_key'        => 'showit_event_dates_start_event',
          'order'           => 'DESC'
        );

    Hope that helps someone

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

The topic ‘Orderby Date Picker in a Group’ is closed to new replies.