S
S
Sergei Gurdjiyan2018-04-24 12:48:14
WordPress
Sergei Gurdjiyan, 2018-04-24 12:48:14

How to sort Wordpress posts by ACF custom field?

The post has a custom field of type Number.
You need to sort the posts, the field of which falls into the desired range.

$args = array(
    'posts_per_page' => 5,
    'cat' => $current_category->term_id,
    'meta_query' => [
        'relation' => 'AND',
        [
            'key' => 'size',
            'value' => 50,
            'compare' => '>'
        ],
        [
            'key' => 'size',
            'value' => 100,
            'compare' => '<=',
        ]
    ]
);
$query = new WP_Query($args);

But there are no such sweats, although there should be.
How to make a selection on a field of type Number?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2018-04-24
@mrKorg

'key'     => 'size,
'value'   =>  array(50, 100 ),
 'type'    => 'NUMERIC',
'compare' => 'BETWEEN'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question