Support

Account

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

  • 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?