Taxonomy count doesn't increment
Support › MB Custom Table › Taxonomy count doesn't incrementResolved
- This topic has 3 replies, 3 voices, and was last updated 6 years, 9 months ago by
Anh Tran.
-
AuthorPosts
-
January 2, 2019 at 10:37 PM #12852
Camilo Mejia
ParticipantI created a custom taxonomy and a custom post type with MB Custom Table. This is the code I'm using for the relationship between the taxonomy and the post:
array( 'id' => 'id_tipo_inmueble', 'name' => 'Tipo de inmueble *', 'type' => 'taxonomy_advanced', 'taxonomy' => 'tipo_inmueble', 'field_type' => 'select', 'required' => true, ),All is working fine, but the term count doesn't increment, so when I made a query with WP_Query_Term without setting hide_empty to false, the result is empty. I don't want to set hide_empty to false because I'm using that query to show a filter, and I don't want to show options without posts associated with that term.
The expected behavior is that every time I create a post with a term, the related term count increment in one.
January 5, 2019 at 7:59 PM #12900Farheen
ParticipantHello
The one persistent numerical thing about post is ID, however it is sequential for all posts, so you will have gaps if using it.
It would be easiest to assign a number and store it in custom field on post creation. Probably take it from an option and increment it there, so that your numbering doesn't shift if you delete a post and such.
January 6, 2019 at 1:47 AM #12902Camilo Mejia
ParticipantFarheen, I'm reporting a bug, not asking about how to do something. When you assign a term to a post, the count field in the term is incremented by one (I'm not talking about the ID field, terms has another field called count). That field track the number of times a term has been assigned to a post. That's a normal behavior of WordPress with the included post type and the categories and tags taxonomies.
When you create a custom post and a custom taxonomy and make a relation between them using Meta Box, all work as expected, except if you use the plugin MB Custom Table. With a custom table, the field count doesn't increment when you assign a term to a post.
January 8, 2019 at 4:06 PM #12949Anh Tran
KeymasterHi Juan,
Thanks for your feedback.
The problem here is the field type is
taxonomy_advanced. This field does not setup a relationship between posts and terms. Instead, it only saves terms' IDs in the custom table (or post meta if you don't use custom table).To setup the correct relationship between posts and terms, please use field type
taxonomy. In this case, the plugin does not save any value. Instead, it only sets the post terms. And thus, the WordPress counter works correctly. -
AuthorPosts
- You must be logged in to reply to this topic.