Getting posts by custom field value

I need to get posts with a price less than or equal to for example ‘1000’.
The price is set in an arbitrary custom field.
Trying to get posts that way.

$posts = new WP_Query( {
‘post_type’ => ‘post’,
‘meta_query’ => array(
‘key’ => ‘price’,
‘compare’ => ‘<=’,
‘value’ => $_GET[‘price’]
),
} );

The problem is that many posts have already been created, in which the price is set in such a way that the word for example “from 1000″is added at the beginning.
And some are simply given the number ‘1000’.
‘value’ is compared to the number in which there is a string and the result is not correct.

Is there any way to get the posts right?
Or do you have to delete lines from custom price fields?

Read more here:: Getting posts by custom field value

Leave a Reply

Your email address will not be published. Required fields are marked *