Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Dieter Jeanty
Dieter Jeanty
292 Points

Woocommerce - WP All import - Only import draft code problem

Hi Treehouse team & community,

I was wondering if someone could help me with this. I am using wp all import to import some products. In total there are 5025 products where 500 are published and the rest is Draft. I am using wp all import to sync the stock but i want to update only the ones that are published so not the draft ones.

I contacted the wp all import team and they gave me half of the code but i can’t figure out the rest Here is what i have and tried: This is my code :

function do_not_update_if_draft($post_id, $data, $import_id)
    // Check for your import
    if ($import_id == 5) {
        // Check if product is draft
        if ( get_post_status ( $ID ) == 'draft' )
            return false;  
        else {
            return true;
add_filter('wp_all_import_is_post_to_update', 'do_not_update_if_draft', 10, 3);

this doesn’t seem to work. they mailed me the following:

"You should be able to get the post status by using the get_post_status function on the $post_id variable, and then storing the result in another variable. You’d then write an if/else statement to check & see if the value in your variable is equal to draft, and return the appropriate value (false if the value is equal to draft, true if it does not equal draft)."

Any ideas how i can make this small problem fixed? Thanks Dieter

The also gave this page as an example: https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/wp_all_import_is_post_to_update.php

Hey Dieter, can you please check the markdown reference and format your code accordingly? People would like to help but it's difficult to read stretches of code in plain text.

Dieter Jeanty
Dieter Jeanty
292 Points

hey @davidwyett , i just updated the post so the code is formatted correctly :-)