Sorting Posts

This is related to ACF Cornerstone Photography Gallery v3

I need to sort the posts for album by modified date OR by menu order. Can you tell me how to do this?

add_filter('cs_looper_custom_topcat', function($result, $args) {
 
  // Check if 'parent_cat' is null and set it to 0 if it is
  $parent_cat = isset($args['parent_cat']) ? $args['parent_cat'] : 0;

  $cat_args = array(
    'hide_empty' => 1,
    'parent' => 0,
    'taxonomy' => 'album'
  );
  
  $parentcats = get_categories($cat_args);
  return $parentcats;

}, 10, 2);


add_filter('cs_looper_custom_parentcat', function($result, $args) {
 
  // Check if 'parent_cat' is null and set it to 0 if it is
  $parent_cat = isset($args['parent_cat']) ? $args['parent_cat'] : 0;

  $cat_args = array(
    'hide_empty' => 1,
    'parent' => $parent_cat,
    'taxonomy' => 'album'
  );
  
  $parentcats = get_categories($cat_args);
  return $parentcats;

}, 10, 2);

Hello Daniel,

Thanks for writing in!

Please refer to this codex:

You may add modified date or menu order argument in your custom PHP code.

Be advised that custom coding is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Best Regards.

Hmm,

I’ve tried this but doesn’t sort any of the posts at all. I’ve tired going into a few posts and setting the order.

$cat_args = array(
    'hide_empty' => 1,
    'parent' => $parent_cat,
    'taxonomy' => 'album',
    'orderby' => 'menu_order', 
    'order' => 'ASEC',

Hey Daniel,

The order is not ASEC it should be ASC. Also, this is a custom PHP code which is beyond the scope of out theme support.

Be advised that custom coding is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

Thank you.

ASC doesn’t work either FYI.

Hi Daniel,

If you have placed the menu order in each of the term items, then it will work. If you did not, replace the menu_order with modified instead.

add_filter('cs_looper_custom_topcat', function($result, $args) {
 
  // Check if 'parent_cat' is null and set it to 0 if it is
  $parent_cat = isset($args['parent_cat']) ? $args['parent_cat'] : 0;

  $cat_args = array(
    'hide_empty' => 1,
    'parent' => 0,
    'taxonomy' => 'album',
    'orderby' => 'modified', // or menu_order
    'order' => 'ASC',
  );
  
  $parentcats = get_categories($cat_args);
  return $parentcats;

}, 10, 2);


add_filter('cs_looper_custom_parentcat', function($result, $args) {
 
  // Check if 'parent_cat' is null and set it to 0 if it is
  $parent_cat = isset($args['parent_cat']) ? $args['parent_cat'] : 0;

  $cat_args = array(
    'hide_empty' => 1,
    'parent' => $parent_cat,
    'taxonomy' => 'album',
    'orderby' => 'modified', // or menu_order
    'order' => 'ASC',
  );
  
  $parentcats = get_categories($cat_args);
  return $parentcats;

}, 10, 2);

Best Regards.

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