Skip to main content
formatting
Source Link
Pim Schaaf
  • 267
  • 1
  • 10

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  
     'orderby' => array( 
        'title' => 'DESC', 
        'menu_order' => 'ASC' 
    )  
);  
$query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array(
'meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => 'city_clause',
) );

This is supported since 4.2.

In your case (edited from your question) I think you would need:

$args = array(
    'post_type' => 'listing',
    'posts_per_page' => 10,
    'paged' => $paged,
    'tax_query' => array(
        array(
            'taxonomy' => 'listingcategory',
            'field'    => 'slug',
            'terms'    => 'commercial',
        )
    ),
    'meta_query' => array(
        'relation' => 'AND',
        'listing_date_clause' => array(
            'key' => 'listing_date',
            'compare' => 'EXISTS',
        ),
        'agreed_date_clause' => array(
            'key' => 'agreed_date',
            'compare' => 'EXISTS',
        ), 
    ),
    'orderby' => array(
        'listing_date_clause' => 'DESC',
        'agreed_date_clause' => 'DESC'
    ),      
);

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ); $query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array(
'meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => 'city_clause',
) );

This is supported since 4.2.

In your case (edited from your question) I think you would need:

$args = array(
    'post_type' => 'listing',
    'posts_per_page' => 10,
    'paged' => $paged,
    'tax_query' => array(
        array(
            'taxonomy' => 'listingcategory',
            'field'    => 'slug',
            'terms'    => 'commercial',
        )
    ),
    'meta_query' => array(
        'relation' => 'AND',
        'listing_date_clause' => array(
            'key' => 'listing_date',
            'compare' => 'EXISTS',
        ),
        'agreed_date_clause' => array(
            'key' => 'agreed_date',
            'compare' => 'EXISTS',
        ), 
    ),
    'orderby' => array(
        'listing_date_clause' => 'DESC',
        'agreed_date_clause' => 'DESC'
    ),      
);

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  
     'orderby' => array( 
        'title' => 'DESC', 
        'menu_order' => 'ASC' 
    )  
);  
$query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array(
'meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => 'city_clause',
) );

This is supported since 4.2.

In your case (edited from your question) I think you would need:

$args = array(
    'post_type' => 'listing',
    'posts_per_page' => 10,
    'paged' => $paged,
    'tax_query' => array(
        array(
            'taxonomy' => 'listingcategory',
            'field'    => 'slug',
            'terms'    => 'commercial',
        )
    ),
    'meta_query' => array(
        'relation' => 'AND',
        'listing_date_clause' => array(
            'key' => 'listing_date',
            'compare' => 'EXISTS',
        ),
        'agreed_date_clause' => array(
            'key' => 'agreed_date',
            'compare' => 'EXISTS',
        ), 
    ),
    'orderby' => array(
        'listing_date_clause' => 'DESC',
        'agreed_date_clause' => 'DESC'
    ),      
);
Added example
Source Link
Pim Schaaf
  • 267
  • 1
  • 10

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ); $query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array ( 
'meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => 'city_clause',
) );

This is supported since 4.2.

In your case (edited from your question) I think you would need:

$args = array(
    'city_clause''post_type' => 'ASC''listing',
    'state_clause''posts_per_page' => 'DESC'10,
    'paged' => $paged,
    'tax_query' => array(
        array(
            'taxonomy' => 'listingcategory',
            'field'    => 'slug',
            'terms'    => 'commercial',
        )
    ),
    'meta_query' => array(
        'relation' => 'AND',
        'listing_date_clause' => array(
            'key' => 'listing_date',
            'compare' => 'EXISTS',
        ),
        'agreed_date_clause' => array(
            'key' => 'agreed_date',
            'compare' => 'EXISTS',
        ), 
    ),
    'orderby' => array(
        'listing_date_clause' => 'DESC',
        'agreed_date_clause' => 'DESC'
    ),      
);

This is supported since 4.2.

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ); $query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array ('meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => array(
    'city_clause' => 'ASC',
    'state_clause' => 'DESC',
),
) );

This is supported since 4.2.

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ); $query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array( 
'meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => 'city_clause',
) );

This is supported since 4.2.

In your case (edited from your question) I think you would need:

$args = array(
    'post_type' => 'listing',
    'posts_per_page' => 10,
    'paged' => $paged,
    'tax_query' => array(
        array(
            'taxonomy' => 'listingcategory',
            'field'    => 'slug',
            'terms'    => 'commercial',
        )
    ),
    'meta_query' => array(
        'relation' => 'AND',
        'listing_date_clause' => array(
            'key' => 'listing_date',
            'compare' => 'EXISTS',
        ),
        'agreed_date_clause' => array(
            'key' => 'agreed_date',
            'compare' => 'EXISTS',
        ), 
    ),
    'orderby' => array(
        'listing_date_clause' => 'DESC',
        'agreed_date_clause' => 'DESC'
    ),      
);
Fixed a syntax error
Source Link
Sumit
  • 4.8k
  • 2
  • 28
  • 36

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ); $query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array'meta_query'array ('meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => array(
    'city_clause' => 'ASC',
    'state_clause' => 'DESC',
),
) );

This is supported since 4.2.

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ); $query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array'meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => array(
    'city_clause' => 'ASC',
    'state_clause' => 'DESC',
),
) );

This is supported since 4.2.

According to https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters you want to specify it similar to the following code example:

$args = array(  'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ); $query = new WP_Query( $args );

This is supported from WordPress 4.0.

For custom fields (post meta) you will need an added meta query, as detailed on https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query

E.g:

$q = new WP_Query( array ('meta_query' => array(
    'relation' => 'AND',
    'state_clause' => array(
        'key' => 'state',
        'value' => 'Wisconsin',
    ),
    'city_clause' => array(
        'key' => 'city',
        'compare' => 'EXISTS',
    ), 
),
'orderby' => array(
    'city_clause' => 'ASC',
    'state_clause' => 'DESC',
),
) );

This is supported since 4.2.

added 10 characters in body
Source Link
Pim Schaaf
  • 267
  • 1
  • 10
Loading
more info for meta queries ; deleted 11 characters in body
Source Link
Pim Schaaf
  • 267
  • 1
  • 10
Loading
Source Link
Pim Schaaf
  • 267
  • 1
  • 10
Loading