BuddyDev

Search

MPP_Gallery_Query class is defined in mediapress/core/common/class-mpp-gallery-query.php. MPP_Gallery_Query extends WP_Query to provide a familiar API for retrieving and listing galleries.

MediaPress uses an object of MPP_Gallery_Query internally to keep track of current page(is single gallery, archive  etc). MediaPress sets up the internal object on MediaPress singleton instance in setup_globals() method in MPP_Core_Component class.

Interacting with MPP_Gallery_Query

In general,  you don’t need to worry about the internals. This class is very useful when you want to retrieve galleries based on certain parameters. Most of the time, you will be using MPP_Gallery_Query while creating a custom gallery loop.

Standard Loop:-

Another Loop:-

Whatever style you like. I recommend the second one.

Multiple Loop:-

Though it is not recommended to create many loops( because each query needs multiple database queries), If needed, you can create as many loop as you want.

Methods & properties:-

It inherits all the properties and methods from WP_Query. Other than that, It adds a few of its own.

query( $args )

It uses parent::query() and only allows limited options with query. Not all WP_Query parameters are supported by MPP_Gallery_Query.

get_galleries()

Equivalent of get_posts()

next_gallery()

Equivalent of next_post()

the_gallery()

Equivalent of the_post(). sets up current gallery.

have_galleries()

Same as have_posts()

rewind_galleries()

Same as rewind_posts()

is_main_query()

Are you working with the MediaPress main gallery query or a custom gallery query.

reset_gallery_data()

Resets current media. same as wp_reset_postdata()

paginate()

Generates pagination links for the current loop.

pagination_count()

prints  the pagination count for the current loop(e.g viewing 1 to 5 of 20 galleries)

get_ids()

Get an array containing all the gallery ids fetched by current query.

Parameters:-

Type parameters

type (array) – array of media types e.g array (‘photo’, ‘audio’, ‘doc’)

Component parameters:-

  • component  (array) – An array of componens( “members”, “groups”, “sitewide”) etc
  • component_id (int) – The numeric id of component for which we are fetching the media. component must be specified.

Status parameters:-

status (array) – Array of statuses. e.g array( “public”, “private”)

Gallery parameters:-

  • id (int) – Gallery id to be fetched. You will most probably never use it as you can fetch single gallery using mpp_get_gallery()
  • in (array) – An array of gallery ids that should be included in the result
  • exclude (array) – An array of gallery ids to be excluded from the result
  • slug (string) – A gallery slug to fetch only this gallery
  • user_id (int) – Any media uploaded by this user
  • user_name (string) – Any media by this user. E.g ‘admin’
  • include_users (array) – An array of user ids whose gallery should be fetched
  • exclude_users (array) – An array of user ids whose gallery should never be included

Date/Time parameters:-

  • year (int) – 4 digit year(e.g. 2016)
  • month (int) – 2 digit month( `1-12)
  • week (int) – Week of the year( 1-53)
  • day (int) – Day of the month. From 1 to 31.

See this link for all supported parameters.

Pagination parameters:-

  • per_page (int) – How many items per page
  • offset (int) – How many items to leave
  • page (int) – Which page of the paged query
  • nopaging (boolean) – Do you need to list all items

Sorting & Order parameters:-

  • order (string) – Sort order. Allowed values “DESC”, “ASC”, default is “DESC”
  • orderby (string) – Field to be used for sorting. It can be none, id, user, title, slug, date,modified, random, comment_count, meta_value,meta_value_num, ids. See this for more.

search_terms (string) – The string to be searched