• Resolved alprio

    (@alprio)


    Hello ,
    I want to add a function to skip certain records that have a custom value but this function must run for a particular import id.

    i added this code , but even if i run another import id , for example import id 20 , the function fires.
    even if i havent add the custom value still fires.

    what am i doing wrong ?

    function is_post_to_update($continue_import, $postid, $data, $import_id) {
        // Retrieve the import ID while the import is running.
        $import_id = wp_all_import_get_import_id(); 
    
        // Check for your import
        if ($import_id == 18) {
            $do_not_update = get_post_meta($postid, 'do_not_update', true);
            if ($do_not_update == true) {
                return false;
            }
            return true;
        }
    }
    add_filter('wp_all_import_is_post_to_update', 'is_post_to_update', 10, 4);
    


    Thank you.

    • This topic was modified 8 months ago by alprio.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @alprio,

    We can’t really help troubleshoot custom code, but one thing I noticed is that your code isn’t returning the original $continue_import value after the IF conditional. It should be something like this:

    function is_post_to_update( $continue_import, $postid, $data, $import_id ) {
    	// Some code here, including an IF conditional
    	
    	// Outside of the IF conditional, return the original value
    	return $continue_import;
    }
    add_filter( 'wp_all_import_is_post_to_update', 'is_post_to_update', 10, 4 );

    Thread Starter alprio

    (@alprio)

    i found a solution .

    function my_is_post_to_update( $continue, $post_id, $xml_node, $import_id ) {
        // Run this code on a specific import
        if ($import_id == '18') {
            // Check if the custom field 'do_not_update' has a value of 'yes'
            $do_not_update_attr = get_post_meta( $post_id, 'do_not_update_attr', true );
            
            // If 'do_not_update' is set to 'yes', don't update this post
            if ( $do_not_update_attr === 'yes' ) {
                return false;
            }
        }
        
        // Continue with the default behavior (update the post)
        return $continue;
    }
    
    add_filter( 'wp_all_import_is_post_to_update', 'my_is_post_to_update', 10, 4 );

    Thank you !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Skip record’ is closed to new replies.