Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Dante › Order archives by menu_order
New Landing › How can we help? › Themeforest Theme Support › Dante › Order archives by menu_order
- This topic has 10 replies, 2 voices, and was last updated 10 years by Mohammad – SUPPORT.
-
Posted in: Dante
-
April 20, 2014 at 10:33 pm #68685
Hello,
by default archives an taxonomy pages seems ordered by creation date.
Where coud we change the loop to order posts by menu_order ?
PS : I’m working with custom post type, custom taxonomies and child theme, but using for now the defaut archives.php code in my custom templates.
April 21, 2014 at 4:53 am #68705Hi,
Please try to use this code at functions.php under child theme directory .add_action('pre_get_posts','alter_query'); function alter_query($query) { global $wp_query; if ( is_archive() ){ $query-> set('post_type' ,'post'); $query-> set('orderby' ,'menu_order'); $query-> set('order' , 'ASC'); } }
Thanks ๐
With Best Regards
Swift IdeasApril 21, 2014 at 9:21 am #68748Hi Mohammad,
I’ve modified the code like this, to apply to my ‘sessions’ custom post type, and to sort by custom field ‘fa_start_datetime’ :
add_action('pre_get_posts','alter_query'); function alter_query($query) { global $wp_query; if ( is_archive() ){ $query-> set('post_type' ,'sessions'); $query-> set('orderby' ,'meta_value name'); $query-> set('meta_key' , 'fc_start_datetime'); $query-> set('order' , 'ASC'); } }
It’s working great but now all my archive pages (even from other post types) are displaying ‘sessions’ !
Also I have some dropdown filters on the right column of archive page and they are not displaying anymore..
I’d like to target order only on archive-sessions.php and taxonomy-sessions_taxonomy.php
Thx )
April 21, 2014 at 9:32 am #68749Ok, I’ve tried
is_post_type_archive( $post_types )
rather thanis_archive()
:add_action('pre_get_posts','alter_query'); function alter_query($query) { global $wp_query; if ( is_post_type_archive( 'sessions' ) ){ //$query-> set('post_type' ,'sessions'); $query-> set('orderby' ,'meta_value name'); $query-> set('meta_key' , 'fc_start_datetime'); $query-> set('order' , 'ASC'); } }
Good points :
– Only custom post type archive and taxonomy archives are affected by the change.
– Other post types archives are not affected by the change.But :
– it kind of breaks the layout (no more main menu displaying, issues in right column, etc…)Any idea ?
April 21, 2014 at 9:34 am #68752Hi,
Where is your website URL so i can check breaking layout ?
Thanks ๐
With Best Regards
Swift IdeasApril 21, 2014 at 9:39 am #68753This reply has been marked as private.April 21, 2014 at 11:01 am #68779Hi there,
Unfortunately that is not part of the current theme functionality, and it’s not within the scope of our support to be able to provide that functionality as it is more work than a small customisation. While we’d love to be able to support every customisation request, we simply don’t have the time. We recommend that you seek a freelance developer if you need that functionality, potentially from one of the below resources:
April 21, 2014 at 4:30 pm #68871Ok thank you
April 21, 2014 at 5:04 pm #68894Hi,
Its ok . You welcome .
Thanks ๐
With Best Regards
Swift IdeasApril 21, 2014 at 7:04 pm #68925Argh, got it..
/* ALTER QUERY FOR SESSIONS ARCHIVES + SESSIONS TAXONOMY ARCHIVES > ORDER BY META_VALUE =================================================================================================== */ function alter_query($query) { if ( is_admin() || ! $query->is_main_query() ) return; global $wp_query; if ( is_post_type_archive( 'sessions' ) ){ $query-> set('post_type' ,'sessions'); $query-> set('orderby' ,'meta_value name'); $query-> set('meta_key' , 'fc_start_datetime'); $query-> set('order' , 'ASC'); } } add_action('pre_get_posts','alter_query'); function alter_query2($query) { if ( is_admin() || ! $query->is_main_query() ) return; global $wp_query; if ( is_tax( 'sessions_taxonomy' ) ){ $query-> set('post_type' ,'sessions'); $query-> set('orderby' ,'meta_value name'); $query-> set('meta_key' , 'fc_start_datetime'); $query-> set('order' , 'ASC'); } } add_action('pre_get_posts','alter_query2');
Adding a !is_admin check resolved the problem of theme breaking
Creating 2 different functions for archives and taxonomy also.April 22, 2014 at 12:34 am #68982Hi,
I’m glad ๐ that issue resolved .Thanks ๐
With Best Regards
Swift Ideas -
Posted in: Dante
You must be logged in and have valid license to reply to this topic.