Home Forums Add-ons Repeater Field Order Repeater Field


Order Repeater Field

  • I would like to order my Repeater Field “telechargement” from the date ($fichier_date) :

    while( have_rows('telechargement') ): the_row(); 
         $fichier_url = get_sub_field('fichier');
         $fichier_titre = get_sub_field('intitule');
         $fichier_date = get_sub_field('date');
    <div><?php echo $fichier_date ?> - <?php echo $fichier_titre; ?></div>
    <?php endwhile; ?>

    Have you an idea ?

  • Hi @jluc73,

    Thanks for the post.

    The first step would involve the creation of a custom filter to replace the standard ‘=’ with ‘LIKE’ in the SQL query, this is to allow for a WILDCARD in the meta_key search.

    The query will look like so:

    // filter
    function my_posts_where( $where ) {
    	$where = str_replace("meta_key = 'dates_%", "meta_key LIKE 'dates_%", $where);
    	return $where;
    add_filter('posts_where', 'my_posts_where');

    You can then order your posts like so:

    $args = array(
    	'numberposts'	=> -1,
    	'post_type'	=> 'post type',
            'orderby'      => 'meta_value'
    	'meta_key'	=> 'telechargement_%_date,
            'order'         => 'ASC'
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Order Repeater Field’ is closed to new replies.