Wpallimport检查按标题重复

我有一个联盟产品Feed,其中包含很多重复的产品。 SKU不同,但图像,标题和说明相同。我正在使用WPallimport。

有人有没有代码检查数据库的重复标题?

iCMS 回答:Wpallimport检查按标题重复

文档中有一个类似的代码片段(请参见下文)。您需要对其进行修改以检查标题而不是自定义字段。

还请注意导入ID的其他检查-您还需要对其进行更新(或删除)。

原始代码段:https://www.wpallimport.com/documentation/developers/code-snippets/#only-create-a-post-if-an-existing-post-doesnt-have-the-same-custom-field-value

function create_only_if_unique_custom_field( $continue_import,$data,$import_id )
{
    // Only run for import ID 1.
    if ($import_id == 1) {

        // The custom field to check.
        $key_to_look_up = "my_custom_field";

        // The value to check where 'num' is the element name.
        $value_to_look_up = $data['num'];

        // Prepare the WP_Query arguments
        $args = array (

            // Set the post type being imported.
            'post_type'  => array( 'post' ),// Check our custom field for our value.
            'meta_query' => array(array(
            'key'        => $key_to_look_up,'value'      => $value_to_look_up,)),);

        // Run the query and do not create post if custom
        // field value is duplicated.
    $query = new WP_Query( $args );
    return !($query->have_posts());

    } else {

        // Take no action if a different import ID is running.
       return $continue_import;

    }
}

add_filter('wp_all_import_is_post_to_create','create_only_if_unique_custom_field',10,3);
本文链接:https://www.f2er.com/2135104.html

大家都在问