Support » Plugin: Media Categories » [media categories] Taxonomy on attachments

  • Resolved stvwlf

    (@stvwlf)


    Hi Eddie – I am @stvwlf who reported the 1.5 bug on Github yesterday. Thank you for fixing that. What I am to say is not specifically about your plugin but an issue I have run into in working with taxonomies on attachment post types, that is, the Media Library.

    I am trying to add a taxonomy filter to the top of the Media Library for my custom taxonomy. In the course of doing this I discovered that WordPress is not incrementing the Media count on the taxonomy terms page. I have the term assigned to several images but WordPress is showing a zero in the Media count column (extreme right on taxonomy page). I disabled your plugin to make sure the plugin was not the source of this – it was not the plugin. Then I disabled my custom taxonomy and assigned the standard category taxonomy to the attachment type. I found that when I assign a POST to a category, the media counter increments, as displayed both under Posts and Media Library (since the same taxonom is assigned to both). However when I assign a category to a Media Library image, the Media count does not increment, stays at zero even though on the Media Library page, on the row for that image it shows me in the category column the image is assigned to that category.

    I checked in the database and the taxonomy tables are correctly updated with the assignment of that term from that taxonomy to that attachment post id.

    The problem is that none of the terms are showing up in the filtering taxonomy dropdown because WordPress sees them as not being assigned to any attachments. I forced the display by overriding Hide Empty and they do show up, but with a post count of zero.

    I am asking you about this because you seem very familiar with the workings of the attachment post type and the media library. Have you run into anything like this? Can you think of anything I might be doing wrong?

    I appreciate any time you put into answering this.
    thank you

    http://wordpress.org/extend/plugins/media-categories-2/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Eddie Moya

    (@eddiemoya)

    With regard to the problem with the counters in the far right column – yes. I have noticed it before. Its some bug with WordPress and I think it extends into other custom post types as well.

    If I have time I will try to look into that problem and submit a patch to core. At that time I will update this post so that can see how it was fixed.

    Im confused about what you talking about with regard to “The problem is that none of the terms are showing up in the filtering taxonomy dropdown.”. Can you clarify?

    I made some further progress with this after what I posted above. I now have the terms correctly appearing in the taxonomy filtering pulldown. However the counts per term reflect only the # of items that have parent posts.

    I determined that the count on a taxonomy associated with the attachment post type only increments when the attachment is attached to a parent post. That is the problem.

    I would like the count on an attachment taxonomy to be updated based on its assignment to images on the media library page and in the media library overlay, whether or not the attachment has a parent post.

    I spent some time tracing the code in the WP source. I found a filter that lets one rewrite the logic for count calculation, update_count_callback. However the sample code I found is geared to using it on post taxonomies not attachments. So far I’ve not figured out how to get it to work on an attachment taxonomy. I have a question up about this here:
    http://wordpress.stackexchange.com/questions/76402/modify-taxonomy-term-count-calculation-on-the-attachment-post-type
    which so far has not received an answer.

    I would like to use the media library as a repository for media, to be able to categorize it with accurate counts, whether or not an attachment post has a parent.

    Thank you for getting back to me – I appreciate it.

    I made some progress with custom code. Since this post has nothing to do with your plugin I am closing it as resolved. Thank you

    Stvwlf, how can I resolve these problems???

    ‘Stvwlf’, how can I resolve these problems?

    I had the same issue with attachments and solved it by replacing the update callback of the “category” taxonomy.

    add the below code to the functions.php of your theme:

    function change_category_arg() {
        global $wp_taxonomies;
        if ( ! taxonomy_exists('category') )
            return false;
    
    	$wp_taxonomies['category']->update_count_callback = '_update_generic_term_count';
    }
    add_action( 'init', 'change_category_arg' );

    This code could be integrated in the register_media_categories function of the plugin.

    rudoka, thank you, I love you. Your solution also works for anyone trying to register a taxonomy with attachments outside this plugin, simply replace ‘category’ with the taxonomy slug.

    Rudoka, thank you. This is the exact method I was looking for several months ago. Appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[media categories] Taxonomy on attachments’ is closed to new replies.