• Resolved byronedwards

    (@byronedwards)


    Hi,

    I have an events metabox where a user can input the dates the event is on using a repeatable field. The group field’s id is ‘_g_dates’.

    This is working well. See working example

    However I can’t create an archive page for the events where they are sorted by the repeatable date. In the example below Id like to show all the events before Jan 1st 2016. But the arguments below return no results. I’m guessing this is because ‘_g_dates’ is an array.

    $args = array(
        'post_type' => 'events',
        'meta_key'  => '_g_dates',
        'orderby'   => 'meta_value_num',
        'order'     => 'ASC',
    
        'meta_query' => array(
            array(
                'key'      => '_g_dates',
                'value'    => '1451520000',
                'compare'  => '<=',
            ),
    
    ));

    See here

    If anyone can point me in the right direction I’d appreciate it (even if it’s “This is the wrong approach, you need to start over”).

    Many thanks,
    ??

    https://www.ads-software.com/plugins/cmb2/

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’m having the same problem. I want to sort the events by start date field within the repeatable group. I have tried various types of queries, including yours, but no luck. I can’t figure out how to get the meta_value field for start date. Also ‘orderby’ => ‘meta_value’ returns the order of SQL meta_value a:9, a:8; a:7, etc.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    byronedwards, You’re issue is resolved in trunk.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    almostworking, please open a new ticket, as what you are doing is fundamentally different from the original poster’s. Also, please include your code.

    @justin Sternberg thank you. I just reposted it.

    Thread Starter byronedwards

    (@byronedwards)

    Hi Justin, thank you but the message in trunk says “Will only work if field is not repeatable or a repeatable group.”

    Mine is a repeatable group.

    $group_field_id = $byron->add_field( array(
    	    'id'          => $prefix . '_g_dates',
    	    'type'        => 'group',
    	    'description' => __( 'Add Event Dates', 'cmb' ),
    	    'options'     => array(
    	        'group_title'   => __( 'Event Date {#}', 'cmb' ), // since version 1.1.4, {#} gets replaced by row number
    	        'add_button'    => __( 'Add Another Date', 'cmb' ),
    	        'remove_button' => __( 'Remove This Date', 'cmb' ),
    	        'sortable'      => false, // beta
    
    	    ),
    	) );
    
    	// Id's for group's fields only need to be unique for the group. Prefix is not needed.
    	$byron->add_group_field( $group_field_id, array(
    	    'name' => 'Event date',
    	    'id'   => 'title',
    	    'desc' => __( 'Uses US format: m/d/Y. Add extra dates by clicking button below', 'cmb2' ),
    	    'type' => 'text_date_timestamp',
    
    	) );
    Plugin Author Justin Sternberg

    (@jtsternberg)

    Ah, I misunderstood. Yah, that’s not currently supported out of the box, though you could make it happen if you felt ambitious.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘sorting by repeatable dates (unix timestamps)’ is closed to new replies.