I have a custom post field that store number like: 1,2,3 and so on. I use Toolset to generate the custom post and field. I want to display all the custom post that have this number value smaller then let's say 2, here is my query, but WordPress doesn't display the correct post:
$args = array(
'post_type' => 'video',
'posts_per_page' => 1,
'no_found_rows' => true,
'meta_query' => array(
array(
'key' => 'wpcf-number',
'value' => 2,
'meta_compare' => '<',
'type' => 'UNSIGNED'
)
)
);
$latest_interview = new WP_Query($args);
echo $latest_interview->request;
This is how the generated SQL appears:
SELECT wpasdasdasd_posts.ID
FROM wpasdasdasd_posts
INNER JOIN wpasdasdasd_postmeta ON ( wpasdasdasd_posts.ID = wpasdasdasd_postmeta.post_id )
WHERE 1=1
AND ( ( wpasdasdasd_postmeta.meta_key = 'wpcf-number' AND CAST(wpasdasdasd_postmeta.meta_value AS UNSIGNED) = '2' ) )
AND wpasdasdasd_posts.post_type = 'video'
AND (wpasdasdasd_posts.post_status = 'publish' OR wpasdasdasd_posts.post_status = 'private')
GROUP BY wpasdasdasd_posts.ID
ORDER BY wpasdasdasd_posts.post_date DESC LIMIT 0, 1
Note that the CAST(mt1.meta_value AS UNSIGNED) = '2' ) is not set to < '2' which seems to me like the logical thing. And WordPress doesn't display what I'm looking for: just one video that has a number smaller then 2.
Running WordPress 5.4 Is there something that I'm doing wrong here ? Thanks !
My issue is resolved now. Thank you!