
-
AuthorPosts
-
April 4, 2022 at 2:22 pm #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.
April 5, 2022 at 8:56 am #1347212Hey 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,
IsmaelApril 25, 2022 at 11:33 am #1349376This 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?
April 25, 2022 at 2:31 pm #1349416Hi,
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,
IsmaelApril 25, 2022 at 2:37 pm #1349417Hi, 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).
April 26, 2022 at 12:58 pm #1349529Hi,
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,
IsmaelApril 26, 2022 at 4:46 pm #1349555This reply has been marked as private.April 27, 2022 at 7:22 am #1349615Hi,
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,
IsmaelApril 27, 2022 at 8:26 am #1349629Oh, my bad. I’ve changed the permissions now.
April 28, 2022 at 8:07 am #1349757Hi,
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,
IsmaelApril 28, 2022 at 2:12 pm #1349822This reply has been marked as private.May 2, 2022 at 6:12 am #1350151Hi,
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,
IsmaelMay 2, 2022 at 10:51 am #1350164This worked perfect – thank you for the assistance!
May 2, 2022 at 12:44 pm #1350175 -
AuthorPosts
- The topic ‘How do I set "page order"’ is closed to new replies.