• Resolved maytro

    (@maytro)


    Hello,

    I’ve created some of category and subcategory in my website.
    The default is to display the category under each video (class=”aiovg-link-category” is by alphabet.
    On category pages, I found how to change it by count instead of the alphabet. But in all the rest I didn’t.

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor wpvideogallery

    (@wpvideogallery)

    Aah. Sorry, the category links displayed under each video doesn’t respond to the categories ordering set in the plugin’s settings page. I promise our next version can do this. Please be patient.

    Thread Starter maytro

    (@maytro)

    And I can’t do that on the server-side? I’m a programmer

    Plugin Contributor wpvideogallery

    (@wpvideogallery)

    You simply need to edit the following template files,

    /wp-content/plugins/all-in-one-video-gallery/public/templates/video-thumbnail.php
    /wp-content/plugins/all-in-one-video-gallery/public/templates/video-thumbnail-image-left.php
    /wp-content/plugins/all-in-one-video-gallery/public/templates/single-video.php

    You may see that our template files use “get_the_terms” function from WordPress to get the categories. Simply follow the tutorial here https://www.yukei.net/2016/04/use-get_the_terms-instead-of-wp_get_object_terms/ that provides the exact steps to change the ordering of the categories.

    Hope, this helped you!

    Thread Starter maytro

    (@maytro)

    Hi,
    Sorry for my messages but there is a problem with the function that you provide.

    This is my code now. Do you recognize my error?

    // using get_the_terms()
     $categories = get_the_terms( get_the_ID(), 'aiovg_categories' );
    // $popular_terms will be ordered alphabetically, so let's order by count
    $categories = usort( $categories, function( $a, $b ){
        if ( $a->count < $b->count ) {
            return 1;
        }
        if ( $a->count > $b->count ) {
            return -1;
        }
        return 0;
    
    } );  
    // we only need slugs, so...
    $categories = wp_list_pluck( $categories, 'names' );
    
                if ( ! empty( $categories ) ) {
                    $meta = array();
                    foreach ( $categories as $category ) {
                        $category_url = aiovg_get_category_page_url( $category );
                        $meta[]       = sprintf( '<a  href="%s" class="aiovg-link-category">%s</a>', esc_url( $category_url ), esc_html( $category->name ) );
                    }
    				
    
    			
    		   printf( '<div class="aiovg-category"><span class="aiovg-icon-folder-open"></span> %s</div>', implode( ', ', $meta ) );
    
    			
                    
                }

    I got these errors:
    1. Warning: Invalid argument supplied for foreach() in /home/media/public_html/materials/wp-includes/class-wp-list-util.php on line 148

    2.

    Warning: Invalid argument supplied for foreach() in /home/media/public_html/materials/wp-content/plugins/all-in-one-video-gallery-premium/public/templates/video-thumbnail.php on line 78

    Plugin Contributor wpvideogallery

    (@wpvideogallery)

    Kindly remove all your code and simply replace the following line,

    $categories = get_the_terms( get_the_ID(), 'aiovg_categories' );

    as

    $categories = wp_get_object_terms( get_the_ID(), 'aiovg_categories', array( 
    'orderby' => 'count',
    'order'   => 'DESC'
    ));

    Hope, this solved your issue!

    Thread Starter maytro

    (@maytro)

    Now it’s work properly!
    I really appreciate the help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Order category by count’ is closed to new replies.