• Resolved m.spierings

    (@mspierings)


    Hi,

    I used this plugin to group media with a ‘slider’ category for my carousel.
    Before, I one of the last updates concerning WP 4.0 I used the function get_cat_ID to get the ID of my category ‘slider’ so that I I could get the attachments related to this Cat.

    However, the taxonomy of the Category created with this plugin has changed from ‘category’ to ‘attachment_category’.

    This will stop the ‘get_cat_ID’ function form working cause it only checks on ‘category’ taxonomy and not on the new ‘attachment_category’.
    My solution is to use the function:
    get_term_by( ‘name’, ‘@your_cat_name’, ‘attachment_category’ )->term_id

    cheers

    https://www.ads-software.com/plugins/media-library-assistant/

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

    (@dglingren)

    Thank you for your message. There may be some confusion about taxonomies used by WordPress and different plugins such as MLA.

    WordPress, of course, provides “Categories” and “Tags”, which are the labels for the category and post_tag taxonomies. Thre are many WordPress functions which use these taxonomies by default. Also by default, these taxonomies are not supported for attachments. Several plugins have extended these taxonomies to attachments.

    There are some issues when the category and post_tag taxonomies are used for attachments. Many WordPress features such as archive pages will only show posts and pages assigned to a term; they exclude attachments.

    MLA does not make any changes to category or post_tag. It provides two additional taxonomies for your convenience; “Att. Categories” and “Att. Tags”, labels for the attachment_category and attachment_tag taxonomies created by MLA and registered for attachments. I have used the “Att.” labels to make it clear that these are separate from the built-in WordPress taxonomies.

    You can add attachment and MLA support for any other taxonomy, including category and post_tag by going to the Settings/Media Library Assistant General tab and scrolling down to the “Taxonomy Support” section. You can use the checkboxes there to activate several MLA features for any of the taxonomies in your application.

    Some people find it useful to use the built-in WordPress taxonomies for their attachments; most people prefer to use the separate “Att.” taxonomies or custom taxonomies of their own. The choice is yours.

    Some of the older WordPress functions can only be used with category or post_tag. The get_cat_ID() function that gave you trouble was introduced in WordPress 1.0.0 according to the Codex. Custom taxonomies were not added to WordPress until version 3.0. Most of the more recent WordPress functions take a taxonomy argument, as your example shows.

    I hope that resolves some of the confusion about taxonomies and how they are supported by MLA. I am marking this topic resolved, but please update it or start a new topic if you have problems with or questions about taxonomies in MLA or any other MLA feature. Thanks for your interest in the plugin.

    Thread Starter m.spierings

    (@mspierings)

    Hi,

    I just wanted to add the the get_cat_ID only works with Category taxonomy but you where ahead of me:)

    Strangely, that when you use get_posts and in the Args you use the term_id of the taxonomy which is of type attachement_category…the get_posts() functions doenst return anything. This does work when taxonomy is a category.
    Strangely it does work when I use get_posts with the category as a slug.

    The reason I brought this up that are previous project I had the same setup with wordpress 3.9 and MLA and I think the taxonomy was a category. It worked well with the get_cat_ID and get_posts. But now I started a new project and reused that code to get the attachments and it didn’t work.
    So I used the get_term_by function to get the correct ID, but then I can’t use that ID in the Arguments for get_posts for the category param. I find this a bit odd.
    But like I said, the slug works too.

    Just a hint, but it might not be a problem in this case. We are using MLA in very complex inviroments, and the “terms” of att Cat and att tags is spoky when a lot of taxonomies are present. This is more a WP issue, not relatied directly to MLA, or Woocommerce or event management or…

    All togheter WP get confused – to make it easy and short to explain.

    So many things just works well if the MLA cat and tags have unique “very unique” slugs.

    We always starts adding “Media documents”, “Media Images” and so on on top level slugs and then “doucumets-invoices” or “images-editorial” to the next level.

    Then a lot of issues dissapear, with WPML, and with custom tax.

    Rename slugs afterwards is tricky if the problem already started to occur. You might delete the hiarky totally and start over.

    Install “post ID” plugin and see if the same ID occurs to ATT cat or terms as another taxomony, or the base categories itselfs.

    As told, permalinks and slugs are not perfect by WordPress…

    / just a hint

    Plugin Author David Lingren

    (@dglingren)

    Thanks to both of you for your updates and additional information.

    The get_posts() function was introduced in WordPress 1.2.0, long before custom taxonomies such as attachment_category were added. The get_posts() Codex page starts with:

    “The most appropriate use for get_posts is to create an array of posts based on a set of parameters. It retrieves a list of recent posts or posts matching this criteria. get_posts can also be used to create Multiple Loops, though a more direct reference to WP_Query using new WP_Query is preferred in this case.” …

    “If you would just like to call an array of posts based on a small and simple set of parameters within a page, then get_posts is your best option.”

    The “Parameters” section of the page lists category but has no mention of custom taxonomies. It does say, however, “For full parameters list see WP_Query.

    In the Codex page for WP_Query you will find separate sections for “Category Parameters”, “Tag Parameters” and “Taxonomy Parameters”. In “Category Parameters we find:

    • cat (int) – use category id.

    If you look through the source code for get_posts() you will find that it translates the category parameter to cat before handing it off to WP_Query. In the “Taxonomy Parameters” section we find:

    • {tax} (string) – use taxonomy slug. Deprecated as of Version 3.1 in favor of ‘tax_query’.

    I make note of these differences in the “MLA Gallery Shortcode” section of the Settings/Media Library Assistant Documentation tab, and I introduced “category” as a synonym for “category_name” after several support topics complaining of odd results. Of course, that only works for the [mla_gallery] shortcode.

    I think that explains the behavior you are seeing, and it is an example of the special treatment that category and post_tag get in many places, just because they are “legacy” taxonomies built-in to WordPress before custom taxonomies were introduced.

    Jonas Lundman’s comments are helpful as well. Have a look at this earlier support topic:

    Categories and Att categories conflict

    If you have a term with the same name in different taxonomies, WordPress will use “shared terms”, assigning the same term and term_id to both of the term-taxonomy elements. This can be confusing, as the Make WordPress Core discussion indicates. Hierarchical taxonomies have a similar issue, but with slugs. Slugs are generated from the term name/title, but they must be unique. If you have terms with identical names under different parents, WordPress will generate unique slugs that can trip you up. For example, if you have parent terms like “Media documents” “Media Images” and under each parent you have a child term named “Invoices”, your slugs will be “invoices” and “invoices-media-images” (assuming you created the child under Media Documents first and then added the child under Media Images).

    As Jonas says, if you have unique names for all of your terms you can avoid these issues, but that may not be appropriate for all applications. You just have to be aware of what is going on inside WordPress.

    I did not find the “post ID” plugin Jonas mentions but I did find “Catch IDs“, which adds an ID column to several admin screens. It will show the term_id for each term in a taxonomy. You can easily see the slug by clicking “Quick Edit” for a term.

    This is a tricky part of WordPress, especially for complex applications with multiple taxonomies and sophisticated hierarchical structures. Thanks again for creating an opportunity to, I hope, shed some light on the topic.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘taxonomy term changed, beware’ is closed to new replies.