Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1347142

    In the masonry there is an option to sort the items using “page order” – where do I set the page order for a portfolio page?

    I’ve looked for answers and found that in the regular WP editor you would be able to go to Screen Options and then select Page Attributes to access the “order” field. I can’t see a way to do the same thing in the Avia Layout builder though.

    #1347212

    Hey rabadang,

    Thank you for the inquiry.

    The portfolio custom post type doesn’t support page order attributes by default but you can enable it using this code in the functions.php file.

    /* Change portfolio post type settings */
    function avf_portfolio_cpt_args_mod($args) {
    	$args['supports'][] = 'page-attributes';
    	return $args;
    }
    add_filter('avf_portfolio_cpt_args', 'avf_portfolio_cpt_args_mod');
    

    Best regards,
    Ismael

    #1349376

    This works well for the Layout builder. It does not seem to make a difference regarding the quick access navigation to the sides when viewing a portfolio page (avia-post-nav)? As far as I can tell these are displayed in the order of publishing date(?).

    Is there a way make them follow the set page order as well?

    #1349416

    Hi,

    Thank you for the update.

    Yes, the post navigation is sorted by date by default but we should be able to adjust it to use the page order by using the get_{$adjacent}_post_sort filter. Please try this code in the functions.php file.

    function avf_post_sort_mod($sort, $post, $order)
    {
        if ('portfolio' === get_post_type()) {
            $sort = "ORDER BY p.post_order $order LIMIT 1";
        }
        return $sort;
    }
    add_filter('get_previous_post_sort', 'avf_post_sort_mod', 10, 3);
    add_filter('get_next_post_sort', 'avf_post_sort_mod', 10, 3);
    

    Best regards,
    Ismael

    #1349417

    Hi, I added the exact code from your answer, but doing so the avia-post-nav elements disappear completely from the portfolio pages (even in the source code).

    #1349529

    Hi,

    Thank you for following up.

    Did you see any errors after adding the code? Please post the WP and FTP details in the private field so that we can test the modification further.

    Best regards,
    Ismael

    #1349555
    This reply has been marked as private.
    #1349615

    Hi,

    Thank you for the info.

    The account above has no administrator rights, so we were not able to access the theme files. Please adjust the user role so that we can access the file editor and adjust the modifications.

    Best regards,
    Ismael

    #1349629

    Oh, my bad. I’ve changed the permissions now.

    #1349757

    Hi,

    We adjusted the query a bit.

    if ('portfolio' === get_post_type()) {
    	       $sort = "ORDER BY p.menu_order $order LIMIT 1";
    	   }
    

    And added this code to enable the post navigation on pages or portfolios with full width elements.

    function avf_post_nav_settings_mod( array $settings ){
    	$settings['is_fullwidth'] = false;		
    	return $settings;
    }
    add_filter( 'avf_post_nav_settings', 'avf_post_nav_settings_mod', 10, 1 );
    

    Best regards,
    Ismael

    #1349822
    This reply has been marked as private.
    #1350151

    Hi,

    We have found another solution in a different thread which might help. Please remove the previous filter from the functions.php file and replace it with this one.

    /**
     * Customize Adjacent Post Link Order
     */
    function wpse73190_gist_adjacent_post_where($sql) {
      if ( !is_main_query() || !is_singular() )
        return $sql;
    
      $the_post = get_post( get_the_ID() );
      $patterns = array();
      $patterns[] = '/post_date/';
      $patterns[] = '/\'[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\'/';
      $replacements = array();
      $replacements[] = 'menu_order';
      $replacements[] = $the_post->menu_order;
      return preg_replace( $patterns, $replacements, $sql );
    }
    add_filter( 'get_next_post_where', 'wpse73190_gist_adjacent_post_where' );
    add_filter( 'get_previous_post_where', 'wpse73190_gist_adjacent_post_where' );
    
    function wpse73190_gist_adjacent_post_sort($sql) {
      if ( !is_main_query() || !is_singular() )
        return $sql;
    
      $pattern = '/post_date/';
      $replacement = 'menu_order';
      return preg_replace( $pattern, $replacement, $sql );
    }
    add_filter( 'get_next_post_sort', 'wpse73190_gist_adjacent_post_sort' );
    add_filter( 'get_previous_post_sort', 'wpse73190_gist_adjacent_post_sort' );
    

    This is based on: https://wordpress.stackexchange.com/questions/73190/can-the-next-prev-post-links-be-ordered-by-menu-order-or-by-a-meta-key

    Best regards,
    Ismael

    #1350164

    This worked perfect – thank you for the assistance!

    #1350175

    Hi,

    Glad to know that this solution is working. Please do not hesitate to open another thread if you have more questions regarding the theme.

    Have a nice day.

    Best regards,
    Ismael

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘How do I set "page order"’ is closed to new replies.