WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
[resolved] meta_query with numeric field not working properly (4 posts)

  1. chlustanec
    Member
    Posted 1 year ago #

    Hi,
    I have a little problem with filtering post through meta_query

    lets say, I have this piece of code

    $args = array(
    	        'posts_per_page'  => '10',
    	        'numberposts'     => '',
    	        'offset'          => 0,
    	        'orderby'         => 'post_date',
    	        'order'           => 'DESC',
    	        'post_type'       => 'property',
    	        'post_status'     => 'publish',
    
                'meta_query' => array(
                    array(
                        'key' => 'wpcf-slae-rent',
                        'value' => $_POST['deal_type'],
                        'compare' => 'IN'),
                    array(
                        'key' => 'wpcf-property-type',
                        'value' => $wpcf_type_filter_values,
                        'compare' => 'IN'),
                    array(
                        'key' => 'wpcf-price',
                        'value' =>  $_POST['price_from'],
                        'compare' => '>=')
                    ),
    	        'suppress_filters' => false );

    Now. Everything works on web launch. All other filters works properly. But when I started test with price filter (it is numeric customm field), it began to be funny. I have one post published for testing with price 18000000. When I insert number 1, it works. It works with numbers 18, 180, ... and 17, 170, 1700, ..., but when i insert 19, 181, 1801, ... it doesnt works. It looks like the filter is comparing numbers from left side. At least results looks like it.

    18(000000) >= 18
    180(00000) >= 180
    1800(0000) >= 1800
    18(000000) >= 17
    180(00000) >= 170
    1800(0000) >= 1700
    18(000000) !>= 19
    180(00000) !>= 350
    1800(0000) !>= 7800

    And I need wordpress to take on mind whole price field.

    I hope that I explained it sufficiently and tah taanybody could point me to right direction :)

    Thanks in advance

    http://wordpress.org/extend/plugins/types/

  2. mbigul
    Member
    Plugin Author

    Posted 1 year ago #

    Dear chlustanec,

    Please explain little more for better understanding.

    [ Signature moderated. ]

  3. brucepearson
    Member
    Plugin Author

    Posted 1 year ago #

    You also need to include the 'type' parameter otherwise alphabetically comparison is done.

    eg.

    array(
    'key' => 'wpcf-price',
    'value' => $_POST['price_from'],
    'compare' => '>=',
    'type' => 'numeric')

    Best regards,
    Bruce

  4. chlustanec
    Member
    Posted 1 year ago #

    hi bruce,
    that's the solution :) Thanks a lot :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic