EDIT:
Now, If i put this code on functions.php
function xgc_filter_archive( $query ) {
if ($query->is_main_query()){
if ( is_admin() ) {
return;
}
if ( is_post_type_archive ('concerts') ) {
if ( 'cat' === $_GET['getby'] ) {
$taxquery = array(
array(
'taxonomy' => 'categories_concerts',
'field' => 'slug',
'terms' => $_GET['cat'],
),
);
$query->set( 'tax_query', $taxquery );
$query->set( 'post_type', 'concerts' );
$query->set( 'posts_per_page', -1 );
$query->set( 'meta_key', 'data_del_concert');
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'DESC' );
}
}
if ( is_post_type_archive ('obres') ) {
if ( 'cat' === $_GET['getby'] ) {
$taxquery = array(
array(
'taxonomy' => 'categories_obres',
'field' => 'slug',
'terms' => $_GET['cat'],
),
)
;
$query->set( 'tax_query', $taxquery );
$query->set( 'post_type', 'obres' );
$query->set( 'posts_per_page', -1 );
$query->set( 'meta_key', 'any');
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'DESC' );
}
}
return $query;
}
}
add_action( 'pre_get_posts', 'xgc_filter_archive');
IF I click the filter button goes well and the order too, but at the begining the order of all posts is wrong. This code isn't working well. Any suggest?
$posts = get_posts(array(
'post_type' => 'obres',
'posts_per_page' => -1,
'meta_key' => 'any',
'orderby' => 'meta_value',
'order' => 'DESC'
));
if( $posts ):
while ( have_posts() ) : the_post();
Thanks