Orderby custom field changes Loop in wordpress

0

In my blog, I have different categories, and in each post I created a custom field with the key posicao with numeric values. This is the code I have

    $query = new WP_Query(array(
        'meta_key'          => 'posicao',
        'orderby'           => 'meta_value_num',
        'order'             => 'ASC'
    ));

    if ( $query->have_posts() ) : 

            while ( $query->have_posts() ) : $query->the_post();

                the_content();>     

            endwhile; 

            wp_reset_postdata();

            else: echo "Não existem artigos";

            endif;

However, on the category page, it does not organize more by category, but rather by the order of the 'keyposition', but it shows all posts of all categories.

So, in the page of a categories, not only shows the posts of the category, but if you shoot the variables, as in the example below, it only shows the posts of the categories, but without the order by posicao

    if (have_posts() ) : 

            while (have_posts() ) : the_post();
    
asked by anonymous 08.05.2015 / 14:20

1 answer

0

I was able to perform with

if (is_category( )) {
  $cat = get_query_var('cat');
  $yourcat = get_category ($cat);
  $yourcats =  $yourcat->slug;

 }

query_posts('category_name='. $yourcats.'&meta_key=posicao&orderby=meta_value_num&order=ASC&posts_per_page=-1'); 
if ( have_posts() ) : while ( have_posts() ) : the_post(); 

    the_content();

endwhile; else: endif; 
    
09.05.2015 / 05:27