Count update for media
-
Hello and thank you for this ability to create custom taxonomies.
However, I am using it just for media and the count of media items in taxonomies is not updated.
Any clues, thanks?
-
@markjl
Thanks for your query.Please check that you are running the latest version (1.2.2). Unfortunately the version 1.2.1 contained a bug that would give this error.
Can you then dump the taxonomy that you have defined for your media and include it here please. This is done on the Admin page Settings -? Custom Taxonomies and when hovering over the custom taxonomy name, clicking on the Export PHP. Yhis will download to your device the setup of your taxonomy.
I’ll be able to use it to recreate locally this aspect of your setup and see in detail what is happening.
Thanks in advance.
Neil JamesHi Neil.
Thanks for responding.
I am using v1.2.2
Here it is …<?php add_action( 'init', 'register_staxo_pack', 10 ); function register_staxo_pack() { register_taxonomy( "pack", array ( 0 => 'attachment', ), array ( 'name' => 'pack', 'description' => '', 'labels' => array ( 'name' => 'pack', 'singular_name' => 'Post Term', 'search_items' => 'Search Terms', 'popular_items' => 'Popular Terms', 'all_items' => 'All Terms', 'parent_item' => 'Parent Term', 'parent_item_colon' => 'Parent Term:', 'edit_item' => 'Edit Term', 'view_item' => 'View Term', 'update_item' => 'Update Term', 'add_new_item' => 'Add New Term', 'new_item_name' => 'New Term Name', 'separate_items_with_commas' => 'Separate terms with commas', 'add_or_remove_items' => 'Add or remove terms', 'choose_from_most_used' => 'Choose from the most used terms', 'not_found' => 'No Terms found', 'no_terms' => 'No Terms', 'items_list_navigation' => 'Terms list navigation', 'items_list' => 'Terms list', 'most_used' => 'Most Used', 'back_to_items' => '← Back to Terms', ), 'public' => true, 'publicly_queryable' => true, 'hierarchical' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_in_quick_edit' => true, 'show_admin_column' => true, 'capabilities' => array ( 'manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts', ), 'rewrite' => false, 'query_var' => 'pack', 'update_count_callback' => '', 'show_in_rest' => true, 'rest_base' => '', 'rest_controller_class' => '', 'sort' => false, ) ); } // Display Terms with Posts: none // Display Terms Before text: pack // Display Terms After text: /**Admin List screens for these post type(s) will have a filter list dropdown: attachment with wp_dropdown_categories parameters: array ( 'taxonomy' => 'pack', 'show_option_all' => 'All Terms', 'orderby' => 'name', 'order' => 'ASC', 'show_count' => false, 'hide_empty' => false, 'hide_if_empty' => false, 'selected' => filter_input( INPUT_GET, \'pack\', FILTER_SANITIZE_STRING ), 'hierarchical' => false, 'name' => 'pack', 'value_field' => 'slug', ) **/ /**Term count callback modified. Applies to posts with status: All except trash **/ /**Terms control parameters set. Applies to posts with status: All statuses except Trash. Notifications only if outside bounds will be given and user cannot change terms. No minimum number of terms. No maximum number of terms. **/
@markjl,
Thanks for your configuration. I have used that on a test environment and can confirm what is going on.What the plug-in does in the Term Count section is to modify the count query of standard Word{ress from being
...post_status = 'publish'..
. to...post_status in (set of statuses)...
The issue that you are having is that the count query of standard WordPress is not what you want.
To be counted, the media item has to be uploaded to a post, that is, it has to have a post parent and the parent’s post_status is used to determine whether it is included in the count. If you initially load the media as media, add the terms, and then attech to a post, then the term will not be counted.
This open issue was raised some 8 years ago as https://core.trac.www.ads-software.com/ticket/22558.
It does give a potential resolution for you to try. Please modify your taxonomy set-up (on the Other tab) to set the update count callback to
_update_generic_term_count
. This will set the count as being the number of times the term is used – irrespective of the status of any posts that it is atteched to.I will reflect on whether I will modify the plug-in to note and/or change its behaviour in some way for attachments as it could give rise to different questions from users.
Hope this is helpful,
Neil JamesThanks Neil.
The count now works correctly after updating count callback to_update_generic_term_count
.Could you advise though.
I would like to view the media attached to the term at https://siteurl/?pack=termvalueBut no media is displayed. I assume the thing is configured to display the attached posts at that urL, not the media.
Can this be changed or is there a shortcode to display media attached to terms?
Thanks@markjl,
If you click on the Count number on the pack Taxonomy page, you will see the linked media.You should also see the hyperlink used https://siteurl/wp_admin/upload.php?pack=termvalue&post_type=attachment
You need to be an admin user though.
I do believe that there are plug-ins to support this, but you’ll need to search them out.
Please would you mark this resolved.
Thanks,
Neil JamesOK will do. I think media library assistant offers display shortcodes. Thanks
- The topic ‘Count update for media’ is closed to new replies.