0

My post has a custom post meta named duration. which has the video duration in seconds. Like,

Post 1's duration: 1

Post 2's duration: 56

Post 3's duration: 155

Post 4's duration: 7

Post 5's duration: 2

My args for wp query:

Array
(
    [post_type] => post
    [posts_per_page] => 45
    [paged] => 0
    [orderby] => modified
    [meta_query] => Array
        (
            [0] => Array
                (
                    [key] => duration
                    [value] => 30
                    [compare] => >=
                )

        )

);

The query returns post 2,3,4 but it should return only post 2 and 3. Any idea?

1 Answer 1

3

The meta type needs to be set as numeric.

'type'    => 'numeric',

The full Query:

Array
(
    [post_type] => post
    [posts_per_page] => 45
    [paged] => 0
    [orderby] => modified
    [meta_query] => Array
        (
            [0] => Array
                (
                    [key] => duration
                    [value] => 30
                    [type] => 'numeric';
                    [compare] => >=
                )

        )

);

Your Answer

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

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