• Resolved Ceyar

    (@ceyar)


    Hello wordpress community!

    I have a problem with my query argumentation. I use a custom fields text to output a value(a price) and this value is an String type. example value: “1500”

    So, I would sort my post with a ‘compare’ => ‘between’.

    The code below display my post where price is between 450 and 900. But whe I want to set my argument to go in example from 450 to 1400, it won’t display somthing more even if there are post with this prices.

    When I use “between” with hundreds numbers it works fine. But when I use 1000 and above, it won’t display anything.

    Is there a problem because I use string with number inside?

    $args = array(
    
    		'post_type' => 'objets-a-louer',
    		'posts_per_page' => '-1',
    		'meta_query' => array(
    			'relation'=>'AND',
    			array(
    			'key'     => 'obj_louer_loyer',
    			'value'   => array( '450', '900' ),
    			'compare' => 'BETWEEN',
    						)
    		), 
    
    	);

    Thank you in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, it’s the string type that’s the problem. Your argument is basically saying get louer posts where custom fields are alphabetically between these string values. Despite the numeric string, they are treated as alphabet characters based on their ASCII value.

    Provide actual numeric arguments for ‘value’ and add 'type' => 'numeric', to the array. I’m pretty sure that the stored values will be type cast as numbers even though they are actually strings. Untested by me, but it should work.

    Thread Starter Ceyar

    (@ceyar)

    Thank you for taking time and explanation. I’ll try and I’ll come back with results 😀

    Thread Starter Ceyar

    (@ceyar)

    It’s working fine! Thank you so much!
    Best regards!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Wp_query arguments strange problem.’ is closed to new replies.