Home Forums Add-ons Repeater Field Query Last Row of a Repeater Field Reply To: Query Last Row of a Repeater Field

  • Hi, so I realised from the comments I still need to query this new field. I’ve added in the query to order posts by date with the newly created field, unfortunately to no avail. Any Ideas:

    add_filter('acf/update_value/name=record', 'my_create_a_usable_field', 10, 3);
    function my_create_a_usable_field($value, $post_id, $field) {
      // $value will hold a nested array with the rows of the repeater
      if (!is_array($value)) {
        // the repeater is empty, bail early
        return $value;
      $last_row = end($value);
      $date_in = $last_row['date_in'];
      // now put it into a different field
      // this field can be used in queries for filtering and sorting
      update_post_meta($post_id, 'filterable_date_in', $date_in);
    // args
    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> 'post',
    	'meta_query'		=> 'filterable_date_in',
    	'order'			=> 'ASC',
    	'orderby'		=> 'meta_value',
    	'meta_type'		=> 'DATETIME'	
    // query
    $the_query = new WP_Query( $args);
  • We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.