Support

Account

Home Forums Front-end Issues Problems to sort results on the front end.

Solving

Problems to sort results on the front end.

  • I am having trouble showing the results of the filters in order of numerical values. In the particular case to appear the highest values after minors. Some numerical values are not in the right order. They are mixed.

    <?php
    $args = array(
    	'post_type' => 'propriedades',
    	'meta_key' => 'valor_da_propriedade',
        'orderby' => 'meta_value meta_value_num',
        'order' => 'DESC',
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'tipo_de_propriedade',
                'value' => 'Apartamento',
                'compare' => '='
            ),
    
            array(
                'key' => 'dormitorios_do_imóvel',
                'value' => '2 Dormitórios',
                'compare' => '='
            )
        )
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 
  • The orderby value you’re using doesn’t really work.

    You should use either 'orderby' => 'meta_value' or 'orderby' => 'meta_value_num'

    WP 4.2 also introduced a better way to order by meta_query fields that is detailed here https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/

  • Now just used meta_value_num worked for numbers up to 999,999.99
    For numbers greater than 999,999.99 example:1,000,000.00 does not work the query they play it in the bottom of the screen.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Problems to sort results on the front end.’ is closed to new replies.