New Landing How can we help? Themeforest Theme Support Dante Order archives by menu_order

Viewing 11 posts - 1 through 11 (of 11 total)
  • Posted in: Dante
  • #68685
    wylesight
    Member
    Post count: 45

    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.

    #68705
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    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 Ideas

    #68748
    wylesight
    Member
    Post count: 45

    Hi 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 )

    #68749
    wylesight
    Member
    Post count: 45

    Ok, 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 ?

    #68752
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Where is your website URL so i can check breaking layout ?
    Thanks ๐Ÿ™‚
    With Best Regards
    Swift Ideas

    #68753
    wylesight
    Member
    Post count: 45
    This reply has been marked as private.
    #68779
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi 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:

    https://codeable.io

    Home


    http://www.microlancer.com

    #68871
    wylesight
    Member
    Post count: 45

    Ok thank you

    #68894
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Its ok . You welcome .
    Thanks ๐Ÿ™‚
    With Best Regards
    Swift Ideas

    #68925
    wylesight
    Member
    Post count: 45

    Argh, 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.

    #68982
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    I’m glad ๐Ÿ™‚ that issue resolved .

    Thanks ๐Ÿ™‚
    With Best Regards
    Swift Ideas

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register