Sort portfolio alphabetically

Hi,

I’m trying to sort the portfolio on a site I’m working on by name in alphabetical order. I’ve searched for a solution however everything I can find seems to be from 2014-2015 and is no longer working.

This is what I tried without luck:
https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwiqs4yT-8rWAhVNyWMKHcSxBoIQFggoMAA&url=https%3A%2F%2Ftheme.co%2Fapex%2Fforums%2Ftopic%2Fsort-portfolio-alphabetically%2F&usg=AFQjCNGPig8Nh3rR9bGdPxwSO1OTaTuMvw

Thanks in advance!

Hi there,

Thanks for writing in.

The _portfolio.php template is still in the same location as previous, with same code as this

  if ( count( $filters ) == 1 && in_array( 'All Categories', $filters ) ) {

    $args = array(
      'post_type'      => 'x-portfolio',
      'posts_per_page' => $count,
      'paged'          => $paged
    );

  } else {

    $args = array(
      'post_type'      => 'x-portfolio',
      'posts_per_page' => $count,
      'paged'          => $paged,
      'tax_query'      => array(
        array(
          'taxonomy' => 'portfolio-category',
          'field'    => 'term_id',
          'terms'    => $filters
        )
      )
    );

  }

Which means, adding 'orderby' =>'title', 'order' => 'ASC' should work as provided in that thread. Though, I couldn’t tell what’s happening on your site. Would you mind providing your site’s URL, admin and FTP login credentials in a secure note? Maybe the child theme is inactive or there is an active cache plugin/feature?

Thanks!

Turns out I was missing the orderby => title line which upon further review was further down in that thread I linked. I must have scrolled over it.

Thanks!

You’re welcome!

I had used the same solution but after the theme update to 6.04 this is not working anymore. The portfolio is blank. I checked the php-file, orderby & order lines are in. When I remove them, the portfolio shows up but ofc not sorted. Any ideas? Thanks!

Hello There,

Thanks for updating this thread. It is blank because it may have trigger a fatal error. Could you please post the code of the portfolio template file in your next reply? Meanwhile, please double check your quotes and commas. Most of the time, invalid quotes or incorrect php syntax will trigger a fatal error.

Please let us know how it goes.

Sorry, I found my error:
I had put the code under the first args array but use some portfolio categories now. So after adding it under the second args array that includes the ‘taxonomy’ => ‘portfolio-category’ (the else part of the if/else statement) it works again. All fine now. :slight_smile:

Glad everything is working fine now.

I am having the same issue getting mine to sort properly… Below is the code i’m trying to use. Have I missed something in the syntax, please let me know. Thanks!

  <?php

  if ( count( $filters ) == 1 && in_array( 'All Categories', $filters ) ) {

    $args = array(
      'post_type'      => 'x-portfolio',
      'posts_per_page' => $count,
      'paged'          => $paged,
      'orderby'        => 'title',
      'order'          => 'ASC'
    );

  } else {

    $args = array(
      'post_type'      => 'x-portfolio',
      'posts_per_page' => $count,
      'paged'          => $paged,
      'tax_query'      => array(
        array(
          'taxonomy' => 'portfolio-category',
          'field'    => 'term_id',
          'terms'    => $filters,
          'orderby'  => 'title',
          'order'    => 'ASC'
        )
      )
    );

  }

  $wp_query = new WP_Query( $args );

  ?>

I have also added the _portfolio.php file to my child theme and the main theme and neither seem to change the sort order of the portfolio items. Thank you in advance!

Hi @partnersinfo

I’ve tested the part of the code you shared from inside the _portfolio.php file and I confirm it’s working fine, if you are sure you are adding the file in the correct path in child theme like this:
/x-child/framework/views/global/_portfolio.php

Then please open a new support thread with your website login details in a “Secure Note”, the reason why I’m asking you to open a new support thread is because “Secure Note” is visible to the original post owner along with our stuff.

Thanks.

Yeah thats the path i’m using. Thanks Alaa, i’ll open a new thread now.

Great! We will be responding your new thread shortly.

Could you let me know of the new thread location? I am trying to do the same thing and also having problems. I have tried adding file to child theme and editing the main theme file directly with no change.

Hi there,

Please check this thread:

In case the issue persists, please post a separate thread.

Hope this helps.