WordPress 4.2之前
WordPress 4.2语言+
这对你意味着什么?
处理拆分
split_shared_term挂钩
选项中存储的术语ID
/** *当共享术语被拆分时,更新featured_tags选项。 * *@param int$term_id以前共享术语的id。 *@param int$new_term_id为$term_taxonomy_id创建的新术语的id。 *受拆分影响的term_taxonomy行的@param int$term_tasonomy_id id。 *拆分术语的@param string$taxonomy分类。 */ 函数wporg_featured_tags_split(int$termid,int$new_termid,int$term_taxonomy_id,string$taxonomy):void{ //我们只关心标签,所以首先要验证分类法是posttag。 if(“post_tag”===$taxonomy){ //获取当前功能标签。 $featured_tags=获取选项('feature_datgs'); //如果更新的术语在数组中,请注意数组键。 $found_term=数组搜索($term_id,$featured_tags,true); if(false!==$found_term){ //更新的术语是一个特色标签! 在数组中替换它,保存新数组。 $featured_tags[$found_term]=$new_term_id; update_option('featured_tags',$featuredtags); } } } add_action('split_shared_term','wporg_featured_tags_split',10,4);
词条ID存储在post meta中
/** *更新页面的相关帖子术语ID * *@param int$term_id以前共享术语的id。 *@param int$new_term_id为$term_taxonomy_id创建的新术语的id。 *受拆分影响的term_taxonomy行的@param int$term_tasonomy_id id。 *拆分术语的@param string$taxonomy分类。 */ 函数wporg_page_related_posts_split(int$termid,int$new_term_id,int$term_taxonomy_id,string$taxonomy):void{ //查找meta_value与旧术语ID匹配的所有页面。 $page_ids=获取文章( 阵列( “post_type”=>“页面”, “字段”=>“id”, “meta_key”=>“meta_ key”, “元值”=>$term_id, ) ); //如果存在这样的页面,请更新每个页面的术语ID。 if($pageid){ foreach($page_id作为$id){ 更新post_meta($id,'meta_key',$new_term_id,$term_id); } } } add_action('split_shared_term','wporg_page_related_posts_split',10,4);
wp_get_split_term函数
拆分共享项
/** *检索有关拆分术语的信息,并使用新的术语ID创建featured_tags选项。 * *@返回void */ 函数wporg_featured_tags_check_split(){ $featured_tag_ids=获取选项('feature_datgs',数组()); //检查是否有任何ID对应于已拆分的post_tag术语。 foreach($featuredtag_id作为$index=>$feature标记id){ $new_term_id=wp_get_split_term($featured_tag_id,'post_tag'); if($new_termid){ $featured_tag_ids[$索引]=$new_term_id; } } //保存 更新选项(“featured_tags”,$featuredtag_id); }