Hello, the documentation for this plugin says I can use ‘category=xxx’ and ‘post_tag=xxx’ to filter galleries using WordPress’ built-in functionality. However, I find that neither of these actually work. ‘tag=xxx’, however, does filter by tag. So, what is the correct way to filter by category?
Thanks for your interest in the plugin and for this question. The “Category” and “Tag” filtering is provided by the WordPress WP_Query class, and the syntax is a bit confusing. You can find the details in the Codex:
Category, in particular, is not what you’d expect. Here are the parameters you can use:
- cat (int) – use category id.
- category_name (string) – use category slug (NOT name).
- category__and (array) – use category id.
- category__in (array) – use category id.
- category__not_in (array) – use category id.
There are several examples in the Codex article.
This question has come up before, and I am planning to add more material to the Settings/Media Library Assistant Documentation tab to better address it. I am also considering adding a “category” parameter as a synonym for “category_name” just to make things easier.
I am marking this topic resolved, but please update it if you have any problems or further questions about filtering by taxonomies like Category and Tag. Thanks for adding your voice to the mix and motivating some MLA improvements.
Thanks, David, but I am still having problems.
For my tag archives, I am using
[mla_gallery tag="'. $tag .'"]
And this works fine. However, for category, I am using:
echo do_shortcode('[mla_gallery category="'. $category_name .'"]');
And this doesn’t filter at all. I have tried echoing $category_name and I know it’s returning the slug, so the shortcode is definitely sending:
For example, yet the result is to get all images in any category. I have also changed the category to be a number, the ID of the category, but this also doesn’t work.
OK, I figured this out. I didn’t understand what you were saying. I know you explained it in another thread, and I didn’t understand it there, either. So I’ll post the solution here, in case anyone else has the same problem.
OK, so: if you are in the category archive (category.php), $cat and $category_name are built-in. you can do
<? echo $cat; ?>and get the ID of the category you’re on. $category_name returns the slug.
So, if you want a gallery of all your images in a given category, on the category archives, you just query the category and define it, like so:
<? echo do_shortcode('[mla_gallery category_name="'. $category_name .'"]')?>
You can also do:
<? echo do_shortcode('[mla_gallery cat="'. $cat .'"]')?>
Whichever you use, make sure it’s symmetrical and you use the same parameter twice.
Thanks for the help!
You’ve got it; thanks for posting the explanation.
The next MLA version will accept “category” as a synonym for “category_name”, because this is a common and entirely understandable thing to try.
I have released MLA v1.90, which adds
categoryas a synonym for
category_name. I hope that will avoid some of the confusion you and others have had in the past. Thanks for motivating an enhancement to the plugin.
I’m having a similar problem as well. But I’ll try to explain it better.
The following links take you to the same set of content.
If you click on any category link in the sidebar, the result is the same.
Needless to say, this is a new problem….
Thank you for your question and for taking the time to post links to your site that illustrate the problem.
I have looked at the pages you linked to. It looks like you are having some sort of problem with the way your theme handles category navigation for blog posts. I don’t see anything related to the Media Library Assistant plugin in the examples you have given.
The WordPress category pages and the Categories widget are designed to work with blog posts and pages. MLA provides support for Media Library items (attachments). You can find more information in this earlier support topic and the other topics it links to:
I regret that I cannot give you any more specific help, because I do not see any connection between your problem and MLA. I hope you can get some help from your site’s developer or the theme author. Good luck with your application, and thanks for your interest in MLA.
- The topic ‘Can't filter by category’ is closed to new replies.