Skip to main content
deleted 55 characters in body
Source Link
$posts$posts_list = get_posts(array(
                        'post_type'         => 'obres',
                        'posts_per_page'    => -1,
                        'meta_key'          => 'any',
                        'orderby'           => 'meta_value',
                        'order'             => 'DESC',
                         ));
                if( $posts$posts_list ): 
                    while ( have_posts() ) : the_post();
$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();
$posts_list = get_posts(array(
                    'post_type'         => 'obres',
                    'posts_per_page'    => -1,
                    'meta_key'          => 'any',
                    'orderby'  => 'meta_value',
                    'order'             => 'DESC',
                     ));
            if( $posts_list ): 
                while ( have_posts() ) : the_post();
added 2164 characters in body
Source Link

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

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

deleted 39 characters in body
Source Link
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 );
                }
        }
        if ( is_post_type_archive ('obres') ) {
            if ( ! is_admin() &&if $query->is_main_query() && !'cat' $query->get(=== 'cat'$_GET['getby'] ) ) {
                        $taxquery = array(
                                array(
                                        'taxonomy' => 'categories_obres',
                                        'field' => 'slug',
                                        'terms' => $_GET['cat'],
                                ),
                        )
                        ;
                        $query->set( 'tax_query', $taxquery );
            }
        }
        return $query;
    }
}
add_action( 'pre_get_posts', 'xgc_filter_archive');
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 );
                }
        }
        if ( is_post_type_archive ('obres') ) {
            if ( ! is_admin() && $query->is_main_query() && ! $query->get( 'cat' ) ) {
                        $taxquery = array(
                                array(
                                        'taxonomy' => 'categories_obres',
                                        'field' => 'slug',
                                        'terms' => $_GET['cat'],
                                ),
                        )
                        ;
                        $query->set( 'tax_query', $taxquery );
            }
        }
        return $query;
    }
}
add_action( 'pre_get_posts', 'xgc_filter_archive');
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 );
                }
        }
        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 );
            }
        }
        return $query;
    }
}
add_action( 'pre_get_posts', 'xgc_filter_archive');
Source Link
Loading