Hi Minoo,
There are multiple ways to do it. Do you want to consider the visibility of media while showing the count or not?If we do not consider the visibility of media, the count will be very efficient.
Hi,
Here are the methods:-1. Without considering privacy mpp_gallery_get_media_count( $gallery_id ) will give the count of all media inside the gallery
2. There is no builtin API for the count with privacy, so we will write a new function like this
function mpp_custom_get_media_count( $gallery_id ) { $gallery = mpp_get_gallery( $gallery_id ); $args = array( 'gallery_id' => $gallery->id, 'status' => mpp_get_accessible_statuses( $gallery->component, $gallery->component_id ), 'fields'=> 'ID', 'per_page' => -1, 'nopaging'=> true, ); $gq = new MPP_Media_Query( $args ); $count = $gq->post_count; return $count; }
and we can use it as we wish. Please do not overuse it, it is database intensive operation.
Hope it helps.
Viewing 6 posts - 1 through 6 (of 6 total)
The topic ‘ [Resolved] Get total elements count inside one gallery (by id)’ is closed to new replies.
This topic is: resolved