wpallimport,仅针对特定分类法运行函数“dont_create_terms”

问题描述

所以,我的编码水平实际上等于零的前缀......

我将 wordpress 与 Wp All Import 插件一起使用,我有代码可以防止 wpallimport 创建新的类别/分类法等。

function dont_create_terms( $term_into,$tx_name ) {

// Check if term exists,checking both top-level and child
// taxonomy terms. 
$term = empty($term_into['parent']) ? term_exists( $term_into['name'],$tx_name,0 ) : term_exists( $term_into['name'],$term_into['parent'] );

// Don't allow WP All Import to create the term if it doesn't
// already exist.
if ( empty($term) and !is_wp_error($term) ) { 
    return false;
}

// If the term already exists assign it.
return $term_into;

}

add_filter( 'pmxi_single_category','dont_create_terms',10,2 ); 

现在,正如标题中所指定的,我必须仅针对某些分类法运行此代码...

我尝试了多种解决方案,最后我尝试添加这一行

   if ($tx_name == 'taxonomyname') {

喜欢这里

    function dont_create_terms( $term_into,$tx_name ) {
        
    // Check if term exists,checking both top-level and child
    // taxonomy terms. 
    $term = empty($term_into['parent']) ? term_exists( $term_into['name'],$term_into['parent'] );

if ($tx_name == 'taxonomyname') {

    
    // Don't allow WP All Import to create the term if it doesn't
    // already exist.
    if ( empty($term) and !is_wp_error($term) ) { 
        return false;
    }

        // If the term already exists assign it.
        return $term_into;
    
    }

add_filter( 'pmxi_single_category',2 ); 

但每次都没有出现。

非常感谢任何帮助,提前感谢大家

编辑:

找到解决方

function dont_create_terms( $term_into ) {
    

// Check if term exists,$term_into['parent'] );

    if ( $tx_name == 'taxonomy_name' ){

// Don't allow WP All Import to create the term if it doesn't
// already exist.
if ( empty($term) and !is_wp_error($term) ) { 
    return false;
}

    // If the term already exists assign it.
    return $term_into;


}

add_filter( 'pmxi_single_category',2 ); 

然后调用函数

[dont_create_terms({yourxmldata[1]})]

编辑 2

它只适用于单个分类法,如果分类法包含多个值则不起作用

再说一次,如果您有任何建议,欢迎您

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)