admin管理员组文章数量:1289601
I'm trying to save some term meta for some custom fields I have added via the [taxonomy]_edit_form_fields
hook, I then save the data from these fields on edit with the hook action edited_[taxonomy]
.
For a few different reasons I'm deleting all term meta via wpdb with my prefix and then looping through $_POST
, finding my prefixed form names and adding the term meta, this works fine on my local environment, but on another environment (and only occasionally) the adding of term meta does not happen, the $wpdb
query still deletes all the term meta first.
It's almost like sometimes $_POST
is empty, but I've caught when it happens and used var_dump
on $_POST
and can see the data is coming through, any help with why this might occasionally happen and potential code edits to stop this occurring?
My code is:
function save_my_taxonomy( $term_id ) {
global $wpdb;
if ( !empty( $_POST ) ) {
// Delete all term meta with my term name (this ensures this if an option was previously populated and no longer is and isn't submitted such as checkboxes, the removal occurs)
$wpdb->query(
$wpdb->prepare(
"DELETE FROM `{$wpdb->prefix}termmeta` WHERE `term_id` = %d AND `meta_key` LIKE %s;",
$term_id,
'my_taxonomy_name_%'
)
);
// Loop all $_POST
foreach ( $_POST as $key => $value ) {
// If my field
if ( strpos( $key, 'my_taxonomy_name_' ) === 0 ) {
update_term_meta( $term_id, $key, $value );
}
}
}
}
add_action( 'edited_my_taxonomy_name', 'save_my_taxonomy' );
本文标签: termsPOST sometimes empty even though isn39t when using editedtaxonomy hook
版权声明:本文标题:terms - $_POST sometimes empty even though isn't when using edited_[taxonomy] hook 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741400901a2376661.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论