Support » Plugin: Media Library Assistant » Can't filter by category

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author David Lingren


    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:

    WP_Query Class Reference

    Category, in particular, is not what you’d expect. Here are the parameters you can use:

    1. cat (int) – use category id.
    2. category_name (string) – use category slug (NOT name).
    3. category__and (array) – use category id.
    4. category__in (array) – use category id.
    5. 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:

    [mla_gallery category="nature"]

    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!

    Plugin Author David Lingren


    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.

    Plugin Author David Lingren


    I have released MLA v1.90, which adds category as 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….

    Plugin Author David Lingren


    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:

    Att Categories menu returns 404 error

    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Can't filter by category’ is closed to new replies.