Sorting Portfolio Items Ascending?

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 under the themes/x-child-integrity-light/framework/views/global/ folder and the main x theme and neither seem to change the sort order of the portfolio items. Thank you in advance!

Hi @partnersinfo

I’ve modified the code in _portfokio.php to be like this:

  <?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'          => 'DESC'
    );

  } else {

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

  }

  $wp_query = new WP_Query( $args );

  ?> 

Now it’s working as intended, note that you have these four portfolio items starting with “ZOTHER” instead of “OTHER” that’s why you will see them at the front.

[links in the Secure Note]

Thanks.

@Alaa Thank you so much for your help! worked perfectly!

You are most welcome. :slight_smile:

Could someone tell me how they fixed this issue? I have done the same exact thing, and the posts are still being sorted by date. Let me know if I need to make a new post with secure note.
Thanks.

Hi @mattkutz,

Make sure the file is placed in the correct folder/path. And please start a new thread regarding this and provide your site’s URL and admin login credentials on the secure note. You can then link that thread to this one.

Thanks!

Can you help me with one last thing that doesn’t seem to be working with the theme? On 4 of the portfolio items, we put a Z in front of them to put them at the bottom since we are sorting based A-Z. However, the portfolio item settings “alternate index title” field is not working to correct this on the main page of the item.

Hi There,

It might be the caching issue.

Could you please try clearing all the caches and check again?

Let us know how it goes!

@thai Tried multiple browsers and clearing cache. The title shows correctly on the main portfolio listings, but not on the portfolio detail page.

Hello @partnersinfo,

Thanks for asking. :slight_smile:

On my end title seems to be showing up fine. I am sharing few screenshots, please check it out and let me know if I a missing something.

Cloudup
Cloudup

Thanks.

the portfolio listings page looks fine, its the actual portfolio detail page that still has the Z on the title…

it is just for the 4 “other” categories that we are trying to list at the bottom of the portfolio page.

Hi,

To remove the Z , you can add the code below in Edit Portfolio > Cornerstone > JS


(function($){

    var val = $(".single-x-portfolio .entry-title").html();
    $(".single-x-portfolio .entry-title").html(val.substring(1, val.length));

})(jQuery);

Hope that helps

@paul,
Thank you so much! I added it to the main X theme options under the global JS and it Worked perfectly!

I take that back @paul.r It looks like that worked, but it removed the first letter of every portfolio entry. Is there a way to make it just look for the portfolio items that start with a Z and remove just the Z?

Fixed this by editing the content-portfolio.php manually and calling on the <?php x_the_alternate_title(); ?> instead of the title itself.

Glad you’e sorted it out.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.