Hello.
I want to order posts by a repeater sub field but i cant find the way…
Pic of fields: click here!
Repeater name: mdb_album
Repeater sub field name: mdb_album_field_number
So i try to add meta_key’ => ‘mdb_album_field_number as this example “Order posts by custom fields” but nothing…
Here is the code that load the post with no order.
$qobj = get_queried_object();
$repeater = get_field('repeater');
$args = array(
'post_type' => 'post',
'posts_per_page' => 999,
//'meta_key' => 'mdb_album_field_number',
'orderby' => 'meta_value',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => $qobj->taxonomy,
'field' => 'id',
'terms' => $qobj->term_id,
)
)
);
$query = new WP_Query( $args );
You cannot order by a repeater sub field. Ordering by any meta field requires that all of the values are stored with the same meta key and this is not how a repeater works. My suggestion is to read this https://acfextras.com/dont-query-repeaters/
I found a nasty js solution which works with tables.
How TO – Sort a Table
This case work nice ONLY if someone loads all the values in the same page.