Support

Account

Forum Replies Created

  • Thanks for this John, I worked this in nicely to an image slider using the Gallery field:

    <div class="page-block-right slide-nav-section">
              <?php 
    $images = get_field('gallery');
    $size = 'large'; 
    if( $images ): ?>
            <?php foreach( $images as $image_id ): ?>
              <input type="radio" id="<?php echo $image_id;?>" name="slider" <?php 
           if ($count == 0) {
             echo 'checked';
           }
            ?> >
               <label for="<?php echo $image_id;?>"></label>
    <div class="slide bg4"><?php echo wp_get_attachment_image( $image_id, $size ); ?></div>
                   <?php $count++; ?>
            <?php endforeach; ?>
    <?php endif; ?>         
          </div>
  • 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);
  • This reply has been marked as private.
Viewing 3 posts - 1 through 3 (of 3 total)

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.