{"id":293,"date":"2016-01-16T17:31:55","date_gmt":"2016-01-16T17:31:55","guid":{"rendered":"http:\/\/buddydev.com\/mediapress\/?p=293"},"modified":"2016-01-16T17:32:32","modified_gmt":"2016-01-16T17:32:32","slug":"mpp_gallery_query","status":"publish","type":"post","link":"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/","title":{"rendered":"MPP_Gallery_Query"},"content":{"rendered":"<p><strong>MPP_Gallery_Query<\/strong> class is defined in mediapress\/core\/common\/class-mpp-gallery-query.php. <strong>MPP_Gallery_Query<\/strong> extends <strong>WP_Query<\/strong> to provide a familiar API for retrieving and listing galleries.<\/p>\n<p>MediaPress uses an object of MPP_Gallery_Query internally to keep track of current page(is single gallery, archive \u00a0etc). MediaPress sets up the internal object on MediaPress singleton instance in <strong>setup_globals<\/strong>() method in<strong> MPP_Core_Component<\/strong> class.<\/p>\n<h3 id=\"interact\">Interacting with MPP_Gallery_Query<\/h3>\n<p>In general, \u00a0you don&#8217;t need to worry about the internals. This class is very useful when you want to retrieve galleries\u00a0based on certain parameters. Most of the time, you will be using <strong>MPP_Gallery_Query<\/strong> while creating a custom gallery\u00a0loop.<\/p>\n<h3 id=\"loop-1\">Standard Loop:-<\/h3>\n<pre class=\"lang:default decode:true\">\/\/ The Query\r\n$the_gallery_query = new MPP_Gallery_Query( $args );\r\n\r\n\/\/ The Loop\r\nif ( $the_gallery_query-&gt;have_galleries() ) {\r\n\techo '&lt;ul&gt;';\r\n\twhile ( $the_gallery_query-&gt;have_galleries() ) {\r\n\t\t$the_gallery_query-&gt;the_gallery();\r\n\t\techo '&lt;li&gt;' . mpp_get_gallery_title() . '&lt;\/li&gt;';\r\n\t}\r\n\techo '&lt;\/ul&gt;';\r\n} else {\r\n\t\/\/ no posts found\r\n}\r\n\/* Restore original galler\/post data *\/\r\nmpp_reset_gallery_data();<\/pre>\n<h3 id=\"loop-2\">Another Loop:-<\/h3>\n<pre class=\"lang:default decode:true\">\/\/ the query\r\n$the_gallery_query = new MPP_Gallery_Query( $args ); ?&gt;\r\n\r\n&lt;?php if ( $the_gallery_query-&gt;have_galleries() ) : ?&gt;\r\n\r\n\t\r\n\t&lt;!-- the loop --&gt;\r\n\t&lt;?php while ( $the_gallery_query-&gt;have_galleries() ) : $the_gallery_query-&gt;the_gallery(); ?&gt;\r\n\t&lt;h2&gt;&lt;?php mpp_get_gallery_title(); ?&gt;&lt;\/h2&gt;\r\n\t&lt;?php endwhile; ?&gt;\r\n\t&lt;!-- end of the loop --&gt;\r\n\r\n\t&lt;?php mpp_reset_gallery_data(); ?&gt;\r\n\r\n&lt;?php else : ?&gt;\r\n\t&lt;p&gt;&lt;?php _e( 'Sorry, no gallery found.' ); ?&gt;&lt;\/p&gt;\r\n&lt;?php endif; ?&gt;\r\n\r\n<\/pre>\n<p>Whatever style you like. I recommend the second one.<\/p>\n<h3>Multiple Loop:-<\/h3>\n<p>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.<\/p>\n<h3 id=\"methods_and_parameters\">Methods &amp; properties:-<\/h3>\n<p>It inherits all the properties and methods from <a href=\"https:\/\/codex.wordpress.org\/Class_Reference\/WP_Query\">WP_Query<\/a>. Other than that, It adds a few of its own.<\/p>\n<p><strong>query( $args )<\/strong><\/p>\n<p>It uses parent::query() and only allows limited options with query. Not all WP_Query parameters are supported by MPP_Gallery_Query.<\/p>\n<p><strong>get_galleries()<\/strong><\/p>\n<p>Equivalent of get_posts()<\/p>\n<p><strong>next_gallery()<\/strong><\/p>\n<p>Equivalent of next_post()<\/p>\n<p><strong>the_gallery()<\/strong><\/p>\n<p>Equivalent of the_post(). sets up current gallery.<\/p>\n<p><strong>have_galleries()<\/strong><\/p>\n<p>Same as have_posts()<\/p>\n<p><strong>rewind_galleries()<\/strong><\/p>\n<p>Same as rewind_posts()<\/p>\n<p><strong>is_main_query()<\/strong><\/p>\n<p>Are you working with the MediaPress main gallery\u00a0query or a custom gallery\u00a0query.<\/p>\n<p><strong>reset_gallery_data()<\/strong><\/p>\n<p>Resets current media. same as wp_reset_postdata()<\/p>\n<p><strong>paginate()<\/strong><\/p>\n<p>Generates pagination links for the current loop.<\/p>\n<p><strong>pagination_count()<\/strong><\/p>\n<p>prints \u00a0the pagination count for the current loop(e.g viewing 1 to 5 of 20 galleries)<\/p>\n<p><strong>get_ids()<\/strong><\/p>\n<p>Get an array containing all the gallery\u00a0ids fetched by current query.<\/p>\n<h3 id=\"parameters\">Parameters:-<\/h3>\n<h4 id=\"type\">Type parameters<\/h4>\n<p><strong>type<\/strong> (array) &#8211; array of media types\u00a0e.g array (&#8216;photo&#8217;, &#8216;audio&#8217;, &#8216;doc&#8217;)<\/p>\n<h4 id=\"component\">Component parameters:-<\/h4>\n<ul>\n<li><strong>component<\/strong> \u00a0(array) &#8211; An array of componens( &#8220;members&#8221;, &#8220;groups&#8221;, &#8220;sitewide&#8221;) etc<\/li>\n<li><strong>component_id<\/strong> (int) &#8211; The numeric id of component for which we are fetching the media. component must be specified.<\/li>\n<\/ul>\n<h4 id=\"status\">Status parameters:-<\/h4>\n<p><strong>status<\/strong> (array) &#8211; Array of statuses. e.g array( &#8220;public&#8221;, &#8220;private&#8221;)<\/p>\n<h4 id=\"media\">Gallery\u00a0parameters:-<\/h4>\n<ul>\n<li><strong>id<\/strong> (int) &#8211; Gallery\u00a0id to be fetched. You will most probably never use it as you can fetch single gallery\u00a0using mpp_get_gallery()<\/li>\n<li><strong>in<\/strong> (array) &#8211; An array of gallery\u00a0ids that should be included in the result<\/li>\n<li><strong>exclud<\/strong>e (array) &#8211; An array of gallery\u00a0ids to be excluded from the result<\/li>\n<li><strong>slug<\/strong> (string) &#8211; A gallery\u00a0slug to fetch only this\u00a0gallery<\/li>\n<\/ul>\n<h4 id=\"gallery\">User parameters:-<\/h4>\n<ul>\n<li><strong>user_id<\/strong> (int) &#8211; Any media uploaded by this user<\/li>\n<li><strong>user_name<\/strong> (string) &#8211; Any media by this user. E.g &#8216;admin&#8217;<\/li>\n<li><strong>include_users<\/strong> (array) &#8211; An array of user ids whose gallery should be fetched<\/li>\n<li><strong>exclude_users<\/strong> (array) &#8211; An array of user ids whose gallery should never be included<\/li>\n<\/ul>\n<h4 id=\"date\">Date\/Time parameters:-<\/h4>\n<ul>\n<li><strong>year<\/strong> (int) &#8211; 4 digit year(e.g. 2016)<\/li>\n<li><strong>month<\/strong> (int) &#8211; 2 digit month( `1-12)<\/li>\n<li><strong>week<\/strong> (int) &#8211; Week of the year( 1-53)<\/li>\n<li><strong>day<\/strong> (int) &#8211; Day of the month. From 1 to 31.<\/li>\n<\/ul>\n<p>See this <a href=\"https:\/\/codex.wordpress.org\/Class_Reference\/WP_Query#Date_Parameters\">link<\/a> for all supported parameters.<\/p>\n<h4 id=\"pagination\">Pagination parameters:-<\/h4>\n<ul>\n<li>per_page (int) &#8211; How many items per page<\/li>\n<li>offset (int) &#8211; How many items to leave<\/li>\n<li>page (int) &#8211; Which page of the paged query<\/li>\n<li>nopaging (boolean) &#8211; Do you need to list all items<\/li>\n<\/ul>\n<h4 id=\"sorting\">Sorting &amp; Order parameters:-<\/h4>\n<ul>\n<li><strong>order<\/strong> (string) &#8211; Sort order. Allowed values &#8220;DESC&#8221;, &#8220;ASC&#8221;, default is &#8220;DESC&#8221;<\/li>\n<li><strong>orderby<\/strong> (string) &#8211; Field to be used for sorting. It can be\u00a0none, id, user, title, slug, date,modified, random, comment_count, meta_value,meta_value_num, ids. See\u00a0<a href=\"https:\/\/codex.wordpress.org\/Class_Reference\/WP_Query#Order_.26_Orderby_Parameters\">this<\/a> for more.<\/li>\n<\/ul>\n<h4 id=\"search\">Search parameters:-<\/h4>\n<p><strong>search_terms<\/strong> (string) &#8211; The string to be searched<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 \u00a0etc). MediaPress sets up the internal object on MediaPress singleton instance in setup_globals() method in MPP_Core_Component class. Interacting with MPP_Gallery_Query &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8202],"tags":[],"class_list":["clearfix","post-293","post","type-post","status-publish","format-standard","hentry","category-core"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MPP_Gallery_Query &#8226; MediaPress | BuddyDev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MPP_Gallery_Query &#8226; MediaPress | BuddyDev\" \/>\n<meta property=\"og:description\" content=\"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 \u00a0etc). MediaPress sets up the internal object on MediaPress singleton instance in setup_globals() method in MPP_Core_Component class. Interacting with MPP_Gallery_Query ...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/\" \/>\n<meta property=\"og:site_name\" content=\"MediaPress | BuddyDev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/bpdev\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-16T17:31:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-01-16T17:32:32+00:00\" \/>\n<meta name=\"author\" content=\"Brajesh Singh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sbrajesh\" \/>\n<meta name=\"twitter:site\" content=\"@buddydev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brajesh Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/\",\"url\":\"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/\",\"name\":\"MPP_Gallery_Query &#8226; MediaPress | BuddyDev\",\"isPartOf\":{\"@id\":\"https:\/\/buddydev.com\/mediapress\/#website\"},\"datePublished\":\"2016-01-16T17:31:55+00:00\",\"dateModified\":\"2016-01-16T17:32:32+00:00\",\"author\":{\"@id\":\"https:\/\/buddydev.com\/mediapress\/#\/schema\/person\/4ebf5f3e519f8cbddc6583e182dbe4fb\"},\"breadcrumb\":{\"@id\":\"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/buddydev.com\/mediapress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MPP_Gallery_Query\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/buddydev.com\/mediapress\/#website\",\"url\":\"https:\/\/buddydev.com\/mediapress\/\",\"name\":\"MediaPress | BuddyDev\",\"description\":\"The Best Media Gallery Plugin For BuddyPress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/buddydev.com\/mediapress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/buddydev.com\/mediapress\/#\/schema\/person\/4ebf5f3e519f8cbddc6583e182dbe4fb\",\"name\":\"Brajesh Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/buddydev.com\/mediapress\/#\/schema\/person\/image\/\",\"url\":\"\/\/www.gravatar.com\/avatar\/2106622ee90d53d15ac1402806616aca?s=96&#038;r=g&#038;d=identicon\",\"contentUrl\":\"\/\/www.gravatar.com\/avatar\/2106622ee90d53d15ac1402806616aca?s=96&#038;r=g&#038;d=identicon\",\"caption\":\"Brajesh Singh\"},\"sameAs\":[\"http:\/\/buddydev.com\/members\/sbrajesh\/\",\"https:\/\/x.com\/sbrajesh\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MPP_Gallery_Query &#8226; MediaPress | BuddyDev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/","og_locale":"en_US","og_type":"article","og_title":"MPP_Gallery_Query &#8226; MediaPress | BuddyDev","og_description":"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 \u00a0etc). MediaPress sets up the internal object on MediaPress singleton instance in setup_globals() method in MPP_Core_Component class. Interacting with MPP_Gallery_Query ...","og_url":"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/","og_site_name":"MediaPress | BuddyDev","article_publisher":"https:\/\/www.facebook.com\/bpdev","article_published_time":"2016-01-16T17:31:55+00:00","article_modified_time":"2016-01-16T17:32:32+00:00","author":"Brajesh Singh","twitter_card":"summary_large_image","twitter_creator":"@sbrajesh","twitter_site":"@buddydev","twitter_misc":{"Written by":"Brajesh Singh","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/","url":"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/","name":"MPP_Gallery_Query &#8226; MediaPress | BuddyDev","isPartOf":{"@id":"https:\/\/buddydev.com\/mediapress\/#website"},"datePublished":"2016-01-16T17:31:55+00:00","dateModified":"2016-01-16T17:32:32+00:00","author":{"@id":"https:\/\/buddydev.com\/mediapress\/#\/schema\/person\/4ebf5f3e519f8cbddc6583e182dbe4fb"},"breadcrumb":{"@id":"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/buddydev.com\/mediapress\/core\/mpp_gallery_query\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/buddydev.com\/mediapress\/"},{"@type":"ListItem","position":2,"name":"MPP_Gallery_Query"}]},{"@type":"WebSite","@id":"https:\/\/buddydev.com\/mediapress\/#website","url":"https:\/\/buddydev.com\/mediapress\/","name":"MediaPress | BuddyDev","description":"The Best Media Gallery Plugin For BuddyPress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/buddydev.com\/mediapress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/buddydev.com\/mediapress\/#\/schema\/person\/4ebf5f3e519f8cbddc6583e182dbe4fb","name":"Brajesh Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/buddydev.com\/mediapress\/#\/schema\/person\/image\/","url":"\/\/www.gravatar.com\/avatar\/2106622ee90d53d15ac1402806616aca?s=96&#038;r=g&#038;d=identicon","contentUrl":"\/\/www.gravatar.com\/avatar\/2106622ee90d53d15ac1402806616aca?s=96&#038;r=g&#038;d=identicon","caption":"Brajesh Singh"},"sameAs":["http:\/\/buddydev.com\/members\/sbrajesh\/","https:\/\/x.com\/sbrajesh"]}]}},"_links":{"self":[{"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/comments?post=293"}],"version-history":[{"count":3,"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":296,"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/posts\/293\/revisions\/296"}],"wp:attachment":[{"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/media?parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/categories?post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buddydev.com\/mediapress\/wp-json\/wp\/v2\/tags?post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}