| Snippet Status | Done |
| Snippet Description | - v1.3 - added prefixes to the rules
- v1.2 - 18 nov
- v1.0 - 17 nov 2025
|
| Snippet Type Code | PHP |
| Snippet URL | |
| Snippet Content | * @version 1.3
* Created: AI (Gemini / GPT-5 Mini) and modified by Toine Branbergen
*/ $args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'fields' => 'ids',
); $product_ids = get_posts( $args );
$redirects = array(); foreach ( $product_ids as $product_id ) {
$current_slug = get_post_field( 'post_name', $product_id );
// Match pattern -[digits][letters] at the end
$pattern = '/-d+[a-z]+$/';
$new_slug = preg_replace( $pattern, '', $current_slug ); if ( $new_slug !== $current_slug ) {
// Prefix old with /product/ and new with full site product URL
$old_url_part = '/product/' . $current_slug . '/';
$new_url_part = 'https://www.website.nl/product/' . $new_slug . '/'; wp_update_post( array(
'ID' => $product_id,
'post_name' => $new_slug,
) );
$redirects[ $old_url_part ] = $new_url_part;
}
}
$lines = array();
foreach ( $redirects as $old => $new ) {
$old_esc = str_replace( "'", "\'", $old );
$new_esc = str_replace( "'", "\'", $new );
$lines[] = " '{$old_esc}' => '{$new_esc}',";
}
$file_content = " |
| Snippet Content CSS | |
| Snippet Content HTML | |
| Snippet Content JS | |
| Snippet Content PHP | * @version 1.3
* Created: AI (Gemini / GPT-5 Mini) and modified by Toine Branbergen
*/ $args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'fields' => 'ids',
); $product_ids = get_posts( $args );
$redirects = array(); foreach ( $product_ids as $product_id ) {
$current_slug = get_post_field( 'post_name', $product_id );
// Match pattern -[digits][letters] at the end
$pattern = '/-d+[a-z]+$/';
$new_slug = preg_replace( $pattern, '', $current_slug ); if ( $new_slug !== $current_slug ) {
// Prefix old with /product/ and new with full site product URL
$old_url_part = '/product/' . $current_slug . '/';
$new_url_part = 'https://www.website.nl/product/' . $new_slug . '/'; wp_update_post( array(
'ID' => $product_id,
'post_name' => $new_slug,
) );
$redirects[ $old_url_part ] = $new_url_part;
}
}
$lines = array();
foreach ( $redirects as $old => $new ) {
$old_esc = str_replace( "'", "\'", $old );
$new_esc = str_replace( "'", "\'", $new );
$lines[] = " '{$old_esc}' => '{$new_esc}',";
}
$file_content = " |
| Particle Snippet in Software | 1 |
| Particle Snippet in Boilerplate | 1 |