Change portfolio filter order, and page land on specific filter option

Hello,

I’m needing some help ordering my portfolio filter options. I came across a previous support post from a few years back that said in order to change the order, you could change two lines in global/portfolio.php to:

$terms = get_terms( 'portfolio-category', array( 'include' => $terms, 'orderby' => 'id' ) );

After that, I created the correct folder path on the server, and uploaded the edited portfolio.php file. However, it hasn’t effected anything, even after deleting and recreating the portfolio categories.

Is there a new, more effective way to do this? I only have 3 portfolio categories, and unfortunately they are part of my clients slogan and must be in the specific order of Shop, Dine, and Play.

Second Question

I have 3 portfolio pages to match those 3 categories. While I would like all the categories viewable, I want them to land on the specific portfolio option when they click a link to the page. From what I’ve noticed, if I only selected one of the portfolio options on the page option, it will load on that category but I cannot view the others if I click their link.

What do I need to do in order to allow viewing of all categories, but to land on a specific category on page load?

Thanks!

Hello There,

Thank you for the clarifications. Regretfully the portfolio filter is used for filter portfolio items when you create a page and assign it with a Layout - Portfolio page template. You can not make a direct link out of it and display only the selected category. Please keep in mind that in the Portfolio Settings (https://prnt.sc/gwddmc), the number of items displayed on the page is set to 24 items by default. These items displayed regardless of the categories. You must understand that the Portfolio Filter will only work out of the 24 items displayed on the page. Clicking on the category name in the filter will not load other items on the page. You will need to click the pagination numbers below (page 1/2/3/4) to load the additional portfolio items.

Since you have created 3 separate portfolio pages to display the items with their respective categories, please disable the Portfolio Filtering instead so that no filter will display on the page.

Hope this make sense.

Thank you for that clarification. What about the first question I asked, about ordering them? I’ll be creating a generic portfolio page that will need to have the filters available, and I need to have them in the assigned order.

Hello There,

To resolved the portfolio filter order, please do the following steps below:
1] Using Notepad or TextEdit or Sublime Text or any text editor, please create a new file in your local machine.
2] Insert the following code into that new file

<?php

// =============================================================================
// VIEWS/GLOBAL/_PORTFOLIO.PHP
// -----------------------------------------------------------------------------
// Includes the portfolio output.
// =============================================================================

$stack    = x_get_stack();
$entry_id = get_the_ID();

global $sitepress;

if ( function_exists( 'icl_object_id' ) && is_callable( array( $sitepress, 'get_current_language' ) ) ) {
	$wpml_post = get_post( icl_object_id( $entry_id, 'page', false, $sitepress->get_current_language() ) );
	$entry_id = $wpml_post->ID;
}

$paged    = ( is_front_page() ) ? get_query_var( 'page' ) : ( ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1 );
$cols     = get_post_meta( $entry_id, '_x_portfolio_columns', true );
$count    = get_post_meta( $entry_id, '_x_portfolio_posts_per_page', true );
$filters  = get_post_meta( $entry_id, '_x_portfolio_category_filters', true );

switch ( $cols ) {
  case 'One'   : $cols = 1; break;
  case 'Two'   : $cols = 2; break;
  case 'Three' : $cols = 3; break;
  case 'Four'  : $cols = 4; break;
}

?>

<?php x_get_view( 'global', '_script', 'isotope-portfolio' ); ?>

<div id="x-iso-container" class="x-iso-container x-iso-container-portfolio cols-<?php echo $cols; ?>">

  <?php

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

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

  } else {

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

  }

  $wp_query = new WP_Query( $args );

  ?>

  <?php if ( $wp_query->have_posts() ) : ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
      <?php if ( $stack != 'ethos' ) : ?>
        <?php x_get_view( $stack, 'content', 'portfolio' ); ?>
      <?php else : ?>
        <?php x_ethos_entry_cover( 'main-content' ); ?>
      <?php endif; ?>
    <?php endwhile; ?>
  <?php endif; ?>

</div>

<?php pagenavi(); ?>
<?php wp_reset_query(); ?>

3] Save the file named as _portfolio.php
4] Upload this file to your server in the child theme’s folder wp-content/themes/x-child/framework/views/global/

You will have to create the folder name because it does not exist in your child theme yet.

Please let us know how it goes.