Support

Account

Home Forums Backend Issues (wp-admin) Queuing custom date fields

Helping

Queuing custom date fields

  • Hello there,

    iam implementing an event managing system and using ACF for all the custom data inside a custom post type. The date(s) selection works like that:

    Times (Repeater)
    -Options(Selection: Individual Dates or Repeating Dates)
    –For individual dates there is another repeater with Date and two time picker (from/to).
    –For repeating dates choose a day of the week and two time picker (from/to).

    Now i have different kind of date incidents on a single post.

    Depending on dates i want those posts to be listed like on this example:

    Monday, 12 Dezember 2016
    – Event1
    – Event2

    Tuesday, 13 Dezember 2016
    – Event1

    Monday, 19 Dezember 2016
    – Event2

    Since event 1 has two individual dates on 12 and 13 dezember i want to see it on each of those days. Event 2 is every monday so it should be listed on every monday as well.

    My question is about how to store those datas for a single post, since i don’t want to duplicate the data only for the dates. Iam thinking of generating an extra SQL-table where i store alle the (past/future) dates for an event, since i can’t see how to solve this easier.

    Do you guys have any cool ideas for me?
    Thanks in advance!!

  • From https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ 4. Sub custom field values i derived the following:

    
    function my_posts_groupby() {
      return '';
    }
    add_filter( 'posts_groupby', 'my_posts_groupby' );
    
    function my_posts_where($where)
    {
      $where = str_replace("meta_key = 'daten_%_datum", "meta_key LIKE 'daten_%_datum", $where);
      return $where;
    }
    
    add_filter('posts_where', 'my_posts_where');
    
    // find todays date
    $date = date('Ymd');
    
    // args
    $args = array(
      'numberposts' => -1,
      'post_type' => 'angebotecpt',
      'meta_query' => array(
        array(
          'key' => 'daten_%_datum',
          'compare' => '!=',
          'value' => $date,
        ))
    );
    
    $query = new WP_Query($args);

    Since i overwrite the my_posts_groupby filter i receive ALL posts (multiple occurence), which are NOT today for now. Thats pretty much what i wanted. But what iam still missing is how i can order those posts in my query for all those custom date fields.

    Wanted result:
    query order:
    Event1:Yesterday
    Event2:Tommorow
    Event1:Day after tommorrow
    and so on

    I think i can use the orderby function for that. Any ideas?

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

The topic ‘Queuing custom date fields’ is closed to new replies.