admin管理员组

文章数量:1415119

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/

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/

Share Improve this question edited Aug 22, 2019 at 19:08 nmr 4,5672 gold badges17 silver badges25 bronze badges asked Aug 22, 2019 at 13:18 Atta Ur Rehman AkbarAtta Ur Rehman Akbar 214 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Use meta_value_num to order by numeric values

本文标签: pluginsOrder posts by meta key ( Using ACF )