Created
August 20, 2018 10:53
-
-
Save markusvonplunkett/bbaa87a8df6f6249c65215d721f85f72 to your computer and use it in GitHub Desktop.
Find any reference to OS or NS in slug and remove. Amend stock status accordingly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(isset($_GET['nuke_os'])){ | |
add_action('init', function(){ | |
$products = get_posts(['post_type' => 'product', 'posts_per_page' => -1]); | |
$q = 0; | |
foreach($products as $product){ | |
$extension = substr($product->post_name, -3); | |
if(in_array($extension, ['-os','-ns'])){ | |
$q++; | |
update_post_meta($product->ID, '_stock_status', 'outofstock'); | |
wp_update_post( array( | |
'ID' => $product->ID, | |
'post_title' => substr($product->post_title, 0, -3), | |
'post_name' => substr($product->post_name, 0, -3) | |
)); | |
} | |
} | |
echo 'TOTAL: '.$q; | |
die(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment