Website Settings

Dondere modus
Hoog contrast
Font grootte
Lees pagina-inhoud
Afdrukken
  • Het is 05-04-2026 en week 14 in de Lente .

Account Settings

Winkelwagen

De winkelwagen is nog leeg

Product export with permalink regex adjustment

Omschrijving

Gebruikt bij Horecakruiden om alle product met een suffix van bijv 450g om te zetten naar zonder om vervolgens met de andere functie Bulk insert safe redirects te importeren in de Safe redirect Manager

Snippet

FieldValue
Snippet StatusDone
Snippet Description
  • v1.3 - added prefixes to the rules
  • v1.2 - 18 nov
  • v1.0 - 17 nov 2025
Snippet Type CodePHP
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 Software1
Particle Snippet in Boilerplate1

Relations

ItemType

Pointing items

ItemTypeCategoryTags
Categorie
Tags, , , ,
URL
TypeSnippet
Time
Price

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Home