P
P
partyzanx2018-06-13 05:07:47
WordPress
partyzanx, 2018-06-13 05:07:47

How to sort posts in wordpress?

Are there any plugins that could do the following sort?
5b207c6f58e08632227167.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sklyarov, 2018-06-13
@partyzanx

First, learn to google in English, your question has already been asked many times and the solution is googled in 2 seconds.
Secondly, in order to do any sorting (including by rating, by other additional fields), it is enough to know how WP Query works.
You need to pass the $_GET parameter to the current page and pick it up in the script.
For example, a piece of code for displaying posts by publication date:

$postsPerPage = 10;
$page = 1;
$query = new WP_Query(array(
    'cat' => 4,
    'post_status' => 'publish',
    'orderby' => $_GET['orderby'],
    'order' => 'ASC',
    'paged' => $page,
    'posts_per_page' => $postsPerPage));

The link itself, to show news by date, will look like site.ru/category/?orderby=publish_date? where the orderby value is exactly what we are passing to the loop. This is just one example. In the case of, say, views, you sort by extra. field (how? google wp query custom fields), since the number of views will be an additional field for you. According to the comments, if I remember correctly, instead orderby=publish_dateof we pass orderby=comments_num, and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question