wp query - WordPress Comments sort by custom meta key

admin2025-06-03  3

I want to sort comments by a number of likes which is saved as a meta_key in the wp_commentmeta table: I have tried two ways but it doesn't sort the comments by most liked comment at the top. Please suggest the solution:

$args = array(
    'post_type' => 'comment',
    'post_status' => 'publish',
    'callback' => 'listingo_comments',
    'meta_key' => 'cld_like_count',
    'orderby' => 'meta_value_num',
    'order'    => 'DESC'             
);

wp_list_comments($args);

// and second way

$query = new WP_Query(array(
                        'post_status'   => 'publish',
                        'post_type'     => 'comment',
                        'callback'      => 'listingo_comments',
                        'orderby'       => 'cld_like_count',
                        'order'         => 'DESC'
                        ));

     wp_list_comments($query);
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748895670a314620.html

最新回复(0)