我尝试将自定义分类分配给page 通过“发布”按钮新增时。
这是功能:
function set_default_object_terms( $id, $post ) {
if ( \'publish\' === $post->post_status ) {
log_me (\'From inside function: \'.__FUNCTION__.\', while I pressed the "publish" button. Post-ID: \'.$id);
$taxonomy_ar = get_terms( \'property-features\', \'\' );
foreach ($taxonomy_ar as $taxonomy_term) {
log_me (\'Inside the function: \'.__FUNCTION__.\' and inside the "foreach"-loop for the ID: \'.$id.\' and Term: \'. $taxonomy_term->name . \' and Post-ID :\'. $post->ID);
wp_set_object_terms( $post->ID, $taxonomy_ar, $taxonomy_term->name, true );
}
}}
这是钩子:add_action( \'save_post\', \'set_default_object_terms\', 100, 2 );
在日志文件中,我添加了日志文件,以确定是否找到了所有值,并找到了所有自定义分类:[13-May-12 16:28] be in function while "publish" is pressed with this id: **64**
[13-May-12 16:28] In the "foreach" with id: 64 and Term: **Kitchen** and Post-ID :**64**
[13-May-12 16:28] In the "foreach" with id: 64 and Term: **Stove** and Post-ID :**64**
[13-May-12 16:28] In the "foreach" with id: 64 and Term: **Pets ok** and Post-ID :**64**
但它没有分配它。有人知道把戏在哪里吗?