• Resolved danilocubrovic

    (@danilocubrovic)


    Thanks for this plugin.
    It works great but we miss few thing so I want to check with you.
    It will be great if possible to sort subcategories by last modified date of newest post in subcategory.
    With that sorting it will be useful to show that date beside that subcategory.
    Is this possible via this plugin? I don’t see it in settings but maybe with some hooks or something similar?

    Thanks, Danilo

Viewing 2 replies - 1 through 2 (of 2 total)
  • Anonymous User 393930

    (@anonymized-393930)

    Thank you for the positive feedback. I looked into your suggestion for sorting the order by the date of the last post in each sub category (and optionally displaying this date) but unfortunately this is not at all supported by the core functions used by this plugin and therefore it is not viable to implement it, sorry.

    Thread Starter danilocubrovic

    (@danilocubrovic)

    Hello again.
    Because this is an important feature for us I had to find some patch for this and found it with use of this solution:
    https://jeffri.me/2012/01/sort-by-latest-post-for-wp_list_categories/

    so i add in function.php

    $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' );
    $clauses = apply_filters( 'terms_clauses', compact( $pieces ), $taxonomies, $args );
    
    	
    
    function filter_term_sort_by_latest_post_clauses( $pieces, $taxonomies, $args )
    {
        global $wpdb;
        if ( in_array('category', $taxonomies) && $args['orderby'] == 'latest_post' )
        {
            $pieces['fields'] .= ", MAX(p.post_date) AS last_date";
            $pieces['join'] .= " JOIN $wpdb->term_relationships AS tr JOIN $wpdb->posts AS p ON p.ID=tr.object_id AND tr.term_taxonomy_id=tt.term_taxonomy_id";
            $pieces['where'] .= " GROUP BY t.term_id";
            $pieces['orderby'] = "ORDER BY last_date";
            $pieces['order'] = "DESC"; // DESC or ASC
        }
        return $pieces;
    }
    add_filter('terms_clauses', 'filter_term_sort_by_latest_post_clauses', 10, 3);

    and changed in your plugin line
    $subs = wp_list_categories(array($parent => $category_id, ‘hide_empty’ => $hide_empty_cats, ‘show_count’ => $show_post_count, ‘exclude’ => $excluded, ‘title_li’ => null, ‘show_option_none’ => ”, ‘echo’ => 0, ‘order’ => $order));

    to
    $subs = wp_list_categories(array($parent => $category_id, ‘hide_empty’ => $hide_empty_cats, ‘show_count’ => $show_post_count, ‘exclude’ => $excluded, ‘title_li’ => null, ‘show_option_none’ => ”, ‘echo’ => 0, ‘orderby’ => ‘latest_post’));

    Can you add this option in your next version of plugin?

    It will be useful for more users but me and we could continue to use your updates if we do not have to change this line.

    Best regards,
    Danilo Cubrovic

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sort by modified date and show date’ is closed to new replies.