当我向自定义帖子类型添加新条目时,会创建新类别。
现在,当我的自定义帖子类型被更改/更新时,我试图更改类别标题,但这段代码根本不起作用。还有什么我可以试试的吗?
function check_values($post_ID, $post_after, $post_before){
$myPostAfter = $post_after;
$myPostBefore = $post_before;
$titleBeforeUpdateID = get_cat_ID( $myPostBefore->post_title );
$catSlug = sanitize_title( $myPostAfter->post_title, \'\' );
if( term_exists($myPostBefore->post_title, \'category\') ):
wp_update_term($titleBeforeUpdateID, array(
\'name\' => $myPostAfter->post_title,
\'slug\' => $catSlug
));
endif;
echo \'Post ID:\';
var_dump($post_ID);
echo \'Post Object AFTER update:\';
var_dump($post_after);
echo \'Post Object BEFORE update:\';
var_dump($post_before);
}
add_action( \'post_updated\', \'check_values\', 10, 3 );
错误:
警告:isset中的偏移量类型非法或中为空。。。\\分类法。php在线239
第239行:
/**
* Checks that the taxonomy name exists.
*
* Formerly is_taxonomy(), introduced in 2.3.0.
*
* @since 3.0.0
*
* @global array $wp_taxonomies The registered taxonomies.
*
* @param string $taxonomy Name of taxonomy object.
* @return bool Whether the taxonomy exists.
*/
function taxonomy_exists( $taxonomy ) {
global $wp_taxonomies;
return isset( $wp_taxonomies[$taxonomy] );
}
但是
$myPostBefore->post_title
和
$myPostAfter->post_title
在var\\u转储中返回字符串。