New Landing How can we help? Themeforest Theme Support Supreme Sort order for Portfolio items

Viewing 9 posts - 1 through 9 (of 9 total)
  • Posted in: Supreme
  • #169918
    jameslane
    Member
    Post count: 3

    Hi Guys,

    I’m trying to change the order of portfolio items so it’s alphabetical. Any ideas how I could do this? I don’t mind changing the code where needed.

    Regards,
    James

    #169968
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please paste this code at functions.php of child theme.

    function sf_portfolio_sort( $query ) {
        
    		$query->set( 'orderby', 'title' );
    		$query->set( 'order', 'ASC' );
            return;
        
    }
    add_action( 'pre_get_posts', 'sf_portfolio_sort', 1 );

    Thanks
    Mohammad

    #170041
    jameslane
    Member
    Post count: 3

    Mohammad, you’re a hero, thank you very much for this!

    Regards,
    James

    #170042
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    You most welcome. I’m glad that issue resolved.
    Thanks 🙂
    With Best Regards
    Mohammad

    #170403
    jameslane
    Member
    Post count: 3

    Hi Mohammad,

    I’ve just noticed that the code has made the ‘latest posts’ appear in alphabetical order too. How would I keep the latest posts as they were?

    Regards,
    James

    #170413
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    Can you try the code below, to only affect the portfolio custom post type?

    
    function sf_portfolio_sort( $query ) {
                 if ( is_singular( 'portfolio' ) ) {    
    		          $query->set( 'orderby', 'title' );
    		          $query->set( 'order', 'ASC' );
                 }
            return;
        
    }
    add_action( 'pre_get_posts', 'sf_portfolio_sort', 1 );

    -Rui

    #170414
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please remove the last code and use the code like this:-

    function sf_portfolio_sort( $query ) {
    if($query->query_vars[‘post_type’]==’portfolio’){
    $query->set( ‘orderby’, ‘title’ );
    $query->set( ‘order’, ‘ASC’ );}
    return;

    }
    add_action( ‘pre_get_posts’, ‘sf_portfolio_sort’, 1 );

    #170424
    jameslane
    Member
    Post count: 3

    That has worked a treat, thank you. Hopefully people will be able to use this in the future if needed and it’s not just me.

    Anyway, thanks again!

    Regards,
    James

    #170425
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    No problem. Glad we could help.
    -Rui

Viewing 9 posts - 1 through 9 (of 9 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