List posts by category

0

I have several posts and some of them have a category called "Highlight" and the others are uncategorized, what I need to do is list all these posts, the first ones always need to be the "Highlight" category regardless of when were posted.

The code I have is simply listing all the posts, I have already tried to use the command oderby only without success, I may have done wrong too.

My code is as follows:

    <?php $posts = get_posts( array('post_type'=>'sala', 'numberposts'=>-1, 'order'=>'ASC') ); ?>
    <?php setup_postdata($post);?>

         <?php foreach($posts as $post):

                   /* mostro salas */

         <?php endforeach;?>

I do not have much experience with Wordpress.

    
asked by anonymous 13.07.2017 / 18:50

1 answer

2

So, the taxonomias of Wordpress was not made to sort and yes to group posts. They are not highly recommended for ordering because the cost of processing is high and depending on how many records your site has it will leave you considerably slower.

What I recommend is Meta Data , because Wordpress supports order by meta data natively.

However, if you still want to sort by taxonomia , you would have to write your own query , for that article shows some examples of how to achieve such a goal.

    
14.07.2017 / 13:53