0

Hey I am using ACF in media library and want to sort media by meta key (that is actually created by ACF). BUT it is not working.

Here is the code:

$gallery_imgs = get_posts(array(
    'post_type'         => 'attachment',
    'posts_per_page'    => -1,
    'post_mime_type'    => 'image',
    'post_status'       => 'inherit',
    'meta_key'      => 'serial_no',
    'orderby'       => 'meta_value', //or 'meta_value_num'
    'order'         => 'ASC',
    'tax_query'         => array(
        array(
            'taxonomy'  => 'gallery_ct_artist_cat',
            'field'     => 'term_id',
            'terms'     => $artist_id
         )
    )
));

for reference please visit this link.http://185.94.230.80/~wwwdevatta/artist-collection/294/

1 Answer 1

1

Use meta_value_num to order by numeric values

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.