Listar posts por categoria

Asked

Viewed 398 times

0

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

The code I have is simply listing all posts, I’ve tried using the command oderby only that without success, I may have done wrong too.

My code is this:

    <?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 don’t have much experience with Wordpress.

1 answer

2


So the taxonomias Wordpress were not made to sort but to group posts. They are not very recommended to sort because the processing cost is high and depending on the amount of records your site has will make it considerably slower.

What I recommend is to use Meta Data, because Wordpress supports sort by target date natively.

However, if you still want to order by taxonomia, you would have to write your own query, that’s what this article shows some examples of how to achieve such a goal.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.