@bekee
$args = [
'posts_per_page' => -1,
'meta_query' => [],
'fields' => 'ids',
'meta_key' => 'helpful-pro',
'orderby' => 'meta_value_num',
'order' => 'DESC',
];
$query = new WP_Query( $args );
if ( $query->found_posts ) {
printf( '<strong>%s</strong><br>', esc_html__( 'Pro:' ) );
foreach ( $query->posts as $post_id ) :
printf( '%s: %d<br>', get_the_title( $post_id ), (int) get_post_meta( $post_id, 'helpful-pro', true ) );
endforeach;
}
$args = [
'posts_per_page' => -1,
'meta_query' => [],
'fields' => 'ids',
'meta_key' => 'helpful-contra',
'orderby' => 'meta_value_num',
'order' => 'DESC',
];
$query = new WP_Query( $args );
if ( $query->found_posts ) {
printf( '<strong>%s</strong><br>', esc_html__( 'Contra:' ) );
foreach ( $query->posts as $post_id ) :
printf( '%s: %d<br>', get_the_title( $post_id ), (int) get_post_meta( $post_id, 'helpful-contra', true ) );
endforeach;
}
I’ve already tested the code on myself. All you have to do is insert the post_type as argument and change the order accordingly (ASC/DESC).
-
This reply was modified 5 years, 5 months ago by
Pixelbart.
-
This reply was modified 5 years, 5 months ago by
Pixelbart.