mysql - WordPress 'Custom Post Type' gets set to wrong Taxonomy Term IDs -
first , foremost, need stress how appreciate takes time respond - in advance, thank you, thank you, thank you!
i feel pictures of great service explaining things, start off, here's of illustration of issue:
http://i.stack.imgur.com/b9oxr.png
preface:
- my site has 400 posts under "dir_listing" custom post type
- each "dir_listing" post can associated terms "listing category" custom taxonomy and/or "listing_region" custom taxonomy
- i have 210 "listing_category" terms, , 155 "listing region" terms
the issue in summary:
when publishing or updating "dir_listing" post type, term ids recorded 'term_relationships' table without issue, , other times recorded erroneously.
even so, when go edit 1 of "dir_listing" post types checkboxes desired parent/child terms correctly marked.
actions related?
a number of "listing_category" terms have been shuffled around. (e.g. parent term has become child term, or vice-versa, or child term has been moved parent.)
both parent & child terms have been renamed without making changes "dir_listing" post types. (i don't think matters, since posts supposed related terms id #)
a number of parent terms , child terms may have been deleted admin-level user. seems happen child-terms of "listing_regions" taxonomy.
how i've investigated / tried fix it:
extensively searched wordpress trac (no similar issues reported)
searched google things *"wordpress tax_input bug"*, "wordpress taxonomy id bug", "wordpress custom taxonomy bug", etc. , found no matching issues
disabled plugins, custom rewrites, , other taxonomies
ensured checkbox inputs had correct taxonomy 'name' , term id 'value'
hacked /wp-admin/includes/post.php core file try fix myself. (no luck.)
posted issue [wordpress "how-to , troubleshooting" forum][3] morning (no replies)
posted issue reddit /r/web_design afternoon (also no replies)
i've spent better part of 8 hours trying determine cause of this, or if i'm missing step using custom mysql query directly list of posts related particular term id.
again, thoughts or suggestions might have appreciated - thanks!
this info might how term_id , and term_taxonomy_id work. seems there lot of conditions effect final outcome of how ids set.
see full reference here: http://phpxref.com/xref/wordpress/wp-includes/taxonomy.php.html#wp_insert_term
also have @ this trac ticket regarding need posts relationship table , of use cases.
get_term($term, $taxonomy, $output = object, $filter = 'raw') x-ref term data database term id. usage of get_term function apply filters term object. possible term object database before applying filters. $term id must part of $taxonomy, database. failure, might able captured hooks. failure same value $wpdb returns get_row method. there 2 hooks, 1 each term, named 'get_term', , second taxonomy name, 'term_$taxonomy'. both hooks gets term object, , taxonomy name parameters. both hooks expected return term object. 'get_term' hook - takes 2 parameters term object , taxonomy name. must return term object. used in get_term() catch-all filter every $term. 'get_$taxonomy' hook - takes 2 parameters term object , taxonomy name. must return term object. $taxonomy taxonomy name, example, if 'category', 'get_category' filter name. useful custom taxonomies or plugging default taxonomies. param: int|object $term if integer, database. if object apply filters , return $term. param: string $taxonomy taxonomy name $term part of. param: string $output constant object, array_a, or array_n param: string $filter optional, default raw or no wordpress defined filter applied. return: mixed|null|wp_error term row database. return null if $term empty. if taxonomy not get_term_by($field, $value, $taxonomy, $output = object, $filter = 'raw') x-ref term data database term field , data. warning: $value not escaped 'name' $field. must yourself, if required. default $field 'id', therefore possible use null field, not recommended so. if $value not exist, return value false. if $taxonomy exists , $field , $value combinations exist, term returned. param: string $field either 'slug', 'name', or 'id' param: string|int $value search term value param: string $taxonomy taxonomy name param: string $output constant object, array_a, or array_n param: string $filter optional, default raw or no wordpress defined filter applied. return: mixed term row database. return false if $taxonomy not exist or $term not found. get_term_children( $term_id, $taxonomy ) x-ref merge term children single array of ids. recursive function merge of children of $term same array of term ids. useful taxonomies hierarchical. return empty array if $term not exist in $taxonomy. param: string $term id of term children param: string $taxonomy taxonomy name return: array|wp_error list of term objects. wp_error returned if $taxonomy not exist
Comments
Post a Comment