How can I sort Custom post archive page?
I have a template for a custom post type and it's working ok, but I need to sort the custom posts and I don't find that option.
How can I do it?
-
Hi,
Do you want to have something like a filter on the Custom Post Archive page? Unfortunately, at the moment isn't possible to filters to the Archive pages. You can add a WP widget but it will display all posts not only the Custom Posts Type.
Thanks!
Best regards,
Sandra0 -
Is there a way to sort via the functions.php? I tried this and it didn't work, but maybe I'm missing something.
In my case:
- custom post type is screenplay
- I want to order by the Post Title
<?php
function slug_order_archive_by_field( $query ) {
//Only do if is main query for a specific cpt's archive.
if ( $query->is_main_query() &&
//@TODO set cpt's name
is_post_type_archive( 'screenplay' ) ) {
//@TODO Set the name of the field we are ordering by
$query->set( 'meta_key', 'post_title' );
//@TODO change order to DESC IF you want to go in reverse order
$query->set( 'order', 'ASC' );
//@TODO uncomment next line IF you want to sort by an integer instead of alphabetically
//$query->set( 'orderby', 'meta_value_num' );
//@TODO uncomment next line IF your sort is based on DATE instead
//$query->set( 'orderby', 'meta_value_date' );
}
}
add_action( 'pre_get_posts', 'slug_order_archive_by_field' );
?>0 -
Hi,
Unfortunately, at the moment isn't possible to sort the posts/custom posts displayed with the Archive element. If you are using the Post element then you can sort them by ID, Title, Date, etc.
Regarding the code you share us - we don't recommend re-write the code provided by Brizy because on each update it will be re-write back and you will need to add it again. Also, can appear some inconveniences or cause some problem on the builder.
Let us know if we can help you with something else.
Best regards,
Sandra0 -
Is it possible yet to sort custom posts in Brizy WP or assets in Brizy Cloud? This seems like a basic functionality for a CMS. If not, what is the default sorting - by publish date?
0 -
Hi Timothy,
The Brizy Archive element allows you to order CPTs and blog posts based on two criteria
- Title: This sorts the CPTs based on the alphabetical order of the first character of the Title
- Date: Date of Publishing

If you would like better control on the sorting order, you could consider using the Post Types Order plugin. This plugin can help rearrange the CPT order manually by dragging and dropping the individual CPTs.

Kindly enable the Archive Drag&Drop option for your CPT in the plugin
0
Please sign in to leave a comment.
Comments
5 comments