How to sort records in taxonomies file archive.php?

The site has a taxonomy with a catalog of products. Not WooCommerce...
In the file archive-catalog.php a catalog of products. The default sort/by date of application.
I need to sort by product name. Or title or in the meta-box (plug-AFC).
Function wp_list_sort makes sorting by title. That's just within one page.
For the catalogue see pagination and each page is sorted individually. And I need to sort on the entire array of catalog. How can I do this?
<div class="catalog_arhiv"> 
<?php $posts = wp_list_sort( $posts, 'post_title', 'ASC', 1 ); ?>

 // Cycle
 if ( have_posts() ) {
 while ( have_posts() ):

<div class="catalog__block" > 
 <div class="catalog__img"> 
 <?php echo get_the_post_thumbnail(get_the_ID()); ?> 
 <a href="<?php echo get_permalink(); ?>" target="_blank">
 <div class="catalog__title">
 <?php the_field('product_name'); ?> 
 } else {// Posts was not found
 // Return the original data post. Reset $post.
<?php the_posts_pagination();?>
April 4th 20 at 12:58
1 answer
April 4th 20 at 13:00
Hi! You can do this using WP_Query.
That it will look like a query with a sort on the desired key. Field AFC will need to add a meta value. Read more about WP_Query here
$posts = new WP_Query([
 // Sort
 'order' => 'ASC',
 'orderby' => 'title'
 // The page number of the pagination(set current)
 'paged' => 2
Thanks for the reply, but unfortunately does not work.
Gives an error on the line 'paged' => 2.
And I don't understand the logic - why set the page number? - dereck.Wintheis commented on April 4th 20 at 13:03
Logic is based on the work of the pagination.
When you request Wordpress gives the first bunch of posts(default 10), respectively, to get the next 10, he makes the padding to 10 records. 'paged' just say what offset you need in the query.

This method works, what has not happened is not clear(in your answer).
Once again I recommend to look at the examples here: - thaddeus.Dool commented on April 4th 20 at 13:06
The error I found was not the comma on the previous line.
Then began to fail in a loop. And nothing gives.

And the idea of giving 10 posts confuses me. It turns out sorting is every 10 minute. But I need to first sort the entire array of records and then they give in finally.

And the examples recommended by you info it is not clear which situation applies. What structure of the output data and then apply? Because WP_Query is not typically used in files of type archive-catalog.php. - dereck.Wintheis commented on April 4th 20 at 13:09

Find more questions by tags WordPress