所以,前缀我的编码级别实际上等于零.
我使用Wordpress与Wp所有导入插件,我有这段代码,以防止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
它只适用于单个分类法,如果分类法包含多个值,则不能工作。
因此,如果您有任何建议,我们欢迎您。
发布于 2022-07-06 10:59:31
正确的方法是编写我们的自定义函数,如下所示:https://www.wpallimport.com/documentation/code-snippets/#reference-taxonomy-terms-by-custom-id
然而,尽管它一点也不优雅,但我已经找到了一种可以适用于某些人的不同的解决方案,这涉及到work的foreach()函数。
这是不灵活的,因为它要求您在文件中添加可能的最大值(例如,本例中6个值的最大值):
{@id} >{值1} {@id} > {Value2} {@id} > {Value3} {@id} > {Value4} {@id} > {Value5} {@id} > {Value6} endforeach
其中{ParentNode/CategoryNode} + @id + Value表示xml文件的这一部分:
<ParentNode>
<CategoryNode id="this-cat-id">
<Value>Your value here</Value>
</CategoryNode>
</ParentNode>重要:这将在导入时生成此错误日志,每次它试图导入一个不存在的值时,导入仍将工作:WARNING: It is necessary to assign a name to this term.。
重要:
(1)在导入设置中,您需要转到“分类法、类别、标签”,并选择“我的文件中包含整个层次结构的元素.”。
(2)然后,通过符号检查“单独的层次组”。
(3) 不检查“只将-cat-name- to -在这里分配给层次结构中的底层术语”。
这是我怎么安排的..。截图WPAllImport
希望这能帮助新来的人!
https://stackoverflow.com/questions/66511507
复制相似问题