Support » Plugin: Media Library Assistant » How to retrieve an attachment’s Att. Category/ies?

  • Resolved papijo

    (@papijo)


    How do I retrieve an attachment’s Att Category/ies using that attachment’s ID?
    That’s to say what is the equivalent to get_the_category( ) for WP’s default categories.
    Thanks in advance!

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

    (@dglingren)

    Thanks for your question. You wrote “equivalent to get_the_category()“, which I understand to mean you are looking for a PHP solution.

    MLA’s Att. Categories and Att. Tags are WordPress custom taxonomies and you can use all of the appropriate API functions to work with them. Here are two functions you can try:

    wp_get_object_terms( $object_ids, $taxonomies, $args )

    get_the_terms( int|object $post, string $taxonomy )

    You can click on the above links to get more information.

    I am marking this topic resolved, but please update it if you have problems or further questions regarding the above suggestions. Thanks for your interest in the plugin.

    papijo

    (@papijo)

    Hi David,
    Many thanks for your speedy reply (as usual!). Yes I need this for a PHP script. Your reply confirms what I had already found, but I was missing the actual name of the ‘Att. Category’ to include in the $taxonomies. Finally found out I had to use ‘attachment_category’!
    The following query works fine for my use:

    $taxonomies = 'attachment_category';
    $terms = wp_get_object_terms( $post_id, $taxonomies);
    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the good news and the solution that worked for you. If there’s anything else I can do, let me know.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to retrieve an attachment’s Att. Category/ies?’ is closed to new replies.