所以,我的编码级别实际上等于零的前缀......
我正在使用带有 Wp All Import 插件的 Wordpress,并且我有这个代码来防止 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'], $tx_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'], $tx_name, 0 ) : term_exists( $term_into['name'], $tx_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', 'dont_create_terms', 10, 2 );
但每次都没有出现。
任何帮助都非常感谢,提前感谢大家
编辑:
找到解决方案
function dont_create_terms( $term_into ) {
// 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'], $tx_name, $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', 'dont_create_terms', 10, 2 );
而不是调用函数:
[dont_create_terms({yourxmldata[1]})]
编辑 2
它仅适用于单个分类法,如果分类法包含多个值,它将不起作用
所以再次,如果您有任何建议,欢迎您