Cannot call multiple galleries per page
-
Hi David,
First of all, I’m enjoying what your plugin can do. Secondly, I apologize for how long this post is going to be.
I’m trying to make a list of PDF files falling under a certain hierarchy. For example, I set up an mla_gallery that displays certain categories based on an AND operator.
This allows me to use categories to display documents that fall under the auspices of a primary category (admin or teacher) and then a secondary category (ie: getting-started, engagement, etc).
The problem is that I need to use multiple mla_galleries per page, and either the shortcode is either not recognizing the other categories, or the PDF files aren’t properly being associated. I really am not sure how to troubleshoot it further.
Here’s my code for the page:
<div> <h2>Teachers</h2> <h3>Getting Started</h3> [mla_gallery post_parent="all" post_mime_type=application/pdf attachment_category=teachers,getting-started tax_operator=AND link=file orderby=title order=desc] <h3>Fostering Engagement</h3> [mla_gallery post_parent="all" post_mime_type=application/pdf attachment_category=teachers,engagement tax_operator=AND link=file orderby=title order=desc] <h2>Administrators</h2> <h3>Getting Started</h3> [mla_gallery post_parent="all" post_mime_type=application/pdf attachment_category=admin,getting-started tax_operator=AND link=file orderby=title order=desc] <h3>Fostering Student Engagement</h3> [mla_gallery post_parent="all" post_mime_type=application/pdf attachment_category=admin,engagement tax_operator=AND link=file orderby=title order=desc] </div>I have one PDF file that is categorized as “admin”, “teacher”, and “getting-started”, and this file displays just fine in the 1st and 4th gallery. However, I have a file that is categorized as “teachers” and “engagement”, but it is not displaying anywhere.
Thank you again, and any directions I can get is greatly appreciated.
-
Thanks for taking the time to put together such a complete statement of your issue, including the source code for the page; long is good!
I copied the code for your page, set up some PDFs with the appropriate
attachment_categoryvalues and ran some tests. Everything seems to work fine on my system. I did notice a teacher/teachers difference in your statement:I have one PDF file that is categorized as “admin”, “teacher”, and “getting-started”, and this file displays just fine in the 1st and 4th gallery. However, I have a file that is categorized as “teachers” and “engagement”, but it is not displaying anywhere.
I would double-check the
attachment_categoryvalues assigned to each document. In the Media/Assistant submenu, you can click on a value in the “Att. Category” column to get a display filtered by each term. Perhaps that will illuminate the problem.If you are still stuck, try adding
mla_debug=trueto the failing[mla_gallery]shortcode. You will see a lot of debug information; paste it into this topic and I can have a look through it.Good luck – let me know how you make out and if I can be of any further help.
Hi David,
Thank you so much for looking over my stuff. I’ve checked all of my category slugs, and everything appears to have been matched up (the teacher/teachers discrepancy was only in my first post). Even so, I’m still terrified that I’ve done something really dumb, like having a typo.
In any case I looked at the debug, but my ability to understand it is limited. Right off the bat I see that the beginning statement for the “not working” gallery is “mla_debug empty gallery”, while the working one does not include it (which makes sense).
In any case, here’s the debug for the working gallery call:
[mla_gallery post_parent="all" post_mime_type=application/pdf attachment_category=teachers,getting-started tax_operator=AND link=file orderby=title order=desc mla_debug=true]Debug:
mla_debug $wp_filter[posts_where] = array ( 2147483647 => array ( 'MLAShortcodes::mla_shortcode_query_posts_where_filter' => array ( 'function' => 'MLAShortcodes::mla_shortcode_query_posts_where_filter', 'accepted_args' => 1, ), ), ) mla_debug $wp_filter[posts_orderby] = array ( 2147483647 => array ( 'MLAShortcodes::mla_shortcode_query_posts_orderby_filter' => array ( 'function' => 'MLAShortcodes::mla_shortcode_query_posts_orderby_filter', 'accepted_args' => 1, ), ), ) mla_debug WHERE filter = ' AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,250) AND object_id = wp_posts.ID ) = 2 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\')))' mla_debug modified WHERE filter = ' AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,250) AND object_id = wp_posts.ID ) = 2 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\')))' mla_debug ORDER BY filter, incoming = 'wp_posts.post_date DESC' Replacement ORDER BY clause = 'wp_posts.post_title DESC' mla_debug posts_clauses filter = array ( 'where' => ' AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,250) AND object_id = wp_posts.ID ) = 2 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\')))', 'groupby' => 'wp_posts.ID', 'join' => ' LEFT JOIN wp_posts AS p2 ON (wp_posts.post_parent = p2.ID) ', 'orderby' => 'wp_posts.post_title DESC', 'distinct' => '', 'fields' => 'wp_posts.*', 'limits' => '', ) mla_debug posts_clauses_request filter = array ( 'where' => ' AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,250) AND object_id = wp_posts.ID ) = 2 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\')))', 'groupby' => 'wp_posts.ID', 'join' => ' LEFT JOIN wp_posts AS p2 ON (wp_posts.post_parent = p2.ID) ', 'orderby' => 'wp_posts.post_title DESC', 'distinct' => '', 'fields' => 'wp_posts.*', 'limits' => '', ) mla_debug query = array ( 'tax_query' => array ( 0 => array ( 'taxonomy' => 'attachment_category', 'field' => 'slug', 'terms' => array ( 0 => 'teachers', 1 => 'getting-started', ), 'operator' => 'AND', ), ), 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'application/pdf', 'nopaging' => true, 'ignore_sticky_posts' => true, 'no_found_rows' => true, ) mla_debug request = 'SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_posts AS p2 ON (wp_posts.post_parent = p2.ID) WHERE 1=1 AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,250) AND object_id = wp_posts.ID ) = 2 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\'))) GROUP BY wp_posts.ID ORDER BY wp_posts.post_title DESC ' mla_debug query_vars = array ( 'tax_query' => array ( 0 => array ( 'taxonomy' => 'attachment_category', 'field' => 'slug', 'terms' => array ( 0 => 'teachers', 1 => 'getting-started', ), 'operator' => 'AND', ), ), 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'application/pdf', 'nopaging' => true, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'error' => '', 'm' => 0, 'p' => 0, 'post_parent' => '', 'subpost' => '', 'subpost_id' => '', 'attachment' => '', 'attachment_id' => 0, 'name' => '', 'static' => '', 'pagename' => '', 'page_id' => 0, 'second' => '', 'minute' => '', 'hour' => '', 'day' => 0, 'monthnum' => 0, 'year' => 0, 'w' => 0, 'category_name' => '', 'tag' => '', 'cat' => '', 'tag_id' => '', 'author_name' => '', 'feed' => '', 'tb' => '', 'paged' => 0, 'comments_popup' => '', 'meta_key' => '', 'meta_value' => '', 'preview' => '', 's' => '', 'sentence' => '', 'fields' => '', 'menu_order' => '', 'category__in' => array ( ), 'category__not_in' => array ( ), 'category__and' => array ( ), 'post__in' => array ( ), 'post__not_in' => array ( ), 'tag__in' => array ( ), 'tag__not_in' => array ( ), 'tag__and' => array ( ), 'tag_slug__in' => array ( ), 'tag_slug__and' => array ( ), 'suppress_filters' => false, 'cache_results' => true, 'update_post_term_cache' => true, 'update_post_meta_cache' => true, 'posts_per_page' => 10, 'comments_per_page' => '50', 'taxonomy' => 'attachment_category', 'term' => 'teachers', 'order' => 'DESC', ) mla_debug post_count = 2 </blockquote> Code for the "not working" call: <code>[mla_gallery post_parent="all" post_mime_type=application/pdf attachment_category=teachers,fostering-engagement tax_operator=AND link=file orderby=title order=desc mla_debug=true]</code> Debug: <blockquote>mla_debug empty gallery, query = array ( 'post_parent' => 'all', 'post_mime_type' => 'application/pdf', 'attachment_category' => 'teachers,fostering-engagement', 'tax_operator' => 'AND', 'link' => 'file', 'orderby' => 'title', 'order' => 'desc', 'mla_debug' => 'true', ) mla_debug $wp_filter[posts_where] = array ( 2147483647 => array ( 'MLAShortcodes::mla_shortcode_query_posts_where_filter' => array ( 'function' => 'MLAShortcodes::mla_shortcode_query_posts_where_filter', 'accepted_args' => 1, ), ), ) mla_debug $wp_filter[posts_orderby] = array ( 2147483647 => array ( 'MLAShortcodes::mla_shortcode_query_posts_orderby_filter' => array ( 'function' => 'MLAShortcodes::mla_shortcode_query_posts_orderby_filter', 'accepted_args' => 1, ), ), ) mla_debug WHERE filter = ' AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,251,256,257) AND object_id = wp_posts.ID ) = 4 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\')))' mla_debug modified WHERE filter = ' AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,251,256,257) AND object_id = wp_posts.ID ) = 4 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\')))' mla_debug ORDER BY filter, incoming = 'wp_posts.post_date DESC' Replacement ORDER BY clause = 'wp_posts.post_title DESC' mla_debug posts_clauses filter = array ( 'where' => ' AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,251,256,257) AND object_id = wp_posts.ID ) = 4 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\')))', 'groupby' => 'wp_posts.ID', 'join' => ' LEFT JOIN wp_posts AS p2 ON (wp_posts.post_parent = p2.ID) ', 'orderby' => 'wp_posts.post_title DESC', 'distinct' => '', 'fields' => 'wp_posts.*', 'limits' => '', ) mla_debug posts_clauses_request filter = array ( 'where' => ' AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,251,256,257) AND object_id = wp_posts.ID ) = 4 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\')))', 'groupby' => 'wp_posts.ID', 'join' => ' LEFT JOIN wp_posts AS p2 ON (wp_posts.post_parent = p2.ID) ', 'orderby' => 'wp_posts.post_title DESC', 'distinct' => '', 'fields' => 'wp_posts.*', 'limits' => '', ) mla_debug query = array ( 'tax_query' => array ( 0 => array ( 'taxonomy' => 'attachment_category', 'field' => 'slug', 'terms' => array ( 0 => 'teachers', 1 => 'fostering-engagement', ), 'operator' => 'AND', ), ), 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'application/pdf', 'nopaging' => true, 'ignore_sticky_posts' => true, 'no_found_rows' => true, ) mla_debug request = 'SELECT wp_posts.* FROM wp_posts LEFT JOIN wp_posts AS p2 ON (wp_posts.post_parent = p2.ID) WHERE 1=1 AND ( ( SELECT COUNT(1) FROM wp_term_relationships WHERE term_taxonomy_id IN (248,251,256,257) AND object_id = wp_posts.ID ) = 4 ) AND (wp_posts.post_mime_type = \'application/pdf\') AND wp_posts.post_type = \'attachment\' AND ((wp_posts.post_status = \'inherit\') OR (wp_posts.post_status = \'inherit\' AND (p2.post_status = \'inherit\'))) GROUP BY wp_posts.ID ORDER BY wp_posts.post_title DESC ' mla_debug query_vars = array ( 'tax_query' => array ( 0 => array ( 'taxonomy' => 'attachment_category', 'field' => 'slug', 'terms' => array ( 0 => 'teachers', 1 => 'fostering-engagement', ), 'operator' => 'AND', ), ), 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'application/pdf', 'nopaging' => true, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'error' => '', 'm' => 0, 'p' => 0, 'post_parent' => '', 'subpost' => '', 'subpost_id' => '', 'attachment' => '', 'attachment_id' => 0, 'name' => '', 'static' => '', 'pagename' => '', 'page_id' => 0, 'second' => '', 'minute' => '', 'hour' => '', 'day' => 0, 'monthnum' => 0, 'year' => 0, 'w' => 0, 'category_name' => '', 'tag' => '', 'cat' => '', 'tag_id' => '', 'author_name' => '', 'feed' => '', 'tb' => '', 'paged' => 0, 'comments_popup' => '', 'meta_key' => '', 'meta_value' => '', 'preview' => '', 's' => '', 'sentence' => '', 'fields' => '', 'menu_order' => '', 'category__in' => array ( ), 'category__not_in' => array ( ), 'category__and' => array ( ), 'post__in' => array ( ), 'post__not_in' => array ( ), 'tag__in' => array ( ), 'tag__not_in' => array ( ), 'tag__and' => array ( ), 'tag_slug__in' => array ( ), 'tag_slug__and' => array ( ), 'suppress_filters' => false, 'cache_results' => true, 'update_post_term_cache' => true, 'update_post_meta_cache' => true, 'posts_per_page' => 10, 'comments_per_page' => '50', 'taxonomy' => 'attachment_category', 'term' => 'teachers', 'order' => 'DESC', ) mla_debug post_count = 0[Please post log files between backticks or use the code button.]
There aren’t a whole lot of people I can turn to for guidance, so I appreciate your time quite thoroughly.
Thanks again.
Well, that’s interesting…
Thanks for posting the
mla_debugoutput, which explains part of the problem. The query that fails is trying to match four terms, not two. Here’s the relevant part of the debug output for the query that works:mla_debug request = 'SELECT ... term_taxonomy_id IN (248,250) ... 'and
mla_debug query_vars = array ( 'tax_query' => array ( 0 => array ( 'taxonomy' => 'attachment_category', 'field' => 'slug', 'terms' => array ( 0 => 'teachers', 1 => 'getting-started', ), 'operator' => 'AND', ), ) ...The corresponding portion for the query that fails is:
mla_debug request = 'SELECT ... term_taxonomy_id IN (248,251,256,257) ... 'and
mla_debug query_vars = array ( 'tax_query' => array ( 0 => array ( 'taxonomy' => 'attachment_category', 'field' => 'slug', 'terms' => array ( 0 => 'teachers', 1 => 'fostering-engagement', ), 'operator' => 'AND', ), ) ...The interesting part is that both of the
tax_queryarrays have two terms, but the failing query has fourterm_taxonomy_idvalues!This is happening because one or both of the terms you specified has children – many teachers probably have children ;-). The WordPress
tax_queryparameters provide aninclude_childrenoption and the default istrue. That’s why the extra two term values have been added to the SQL statement.This is an oversight on my part and I will add a parameter to the
[mla_gallery]shortcode to specify theinclude_childrenoption. In the interim, you can avoid the problem by changing your shortcodes to use thetax_querysyntax and specify the behavior you want. For example, change the failing shortcode above to:[mla_gallery post_parent=all post_mime_type=application/pdf link=file orderby=title order=desc tax_query="array(array( 'taxonomy' => 'attachment_category', 'field' => 'slug', 'terms' => array ('teachers','getting-started'), 'operator' => 'AND', 'include_children' => false ) )"]If you get an “ERROR: invalid mla_gallery tax_query” message, check your syntax very carefully; there are lots of punctuation and parentheses that have to be exactly right.
Thanks for providing all the information required to clarify the issue and help me find the cause. I’m going to mark this issue resolved, but feel free to re-open it if you have any more issues or questions.
Huh. Cool.
I’ll give it a shot and see how it turns out.
Thank you again!
The topic ‘Cannot call multiple galleries per page’ is closed to new replies.