I want to change the slugs of my terms dynamically
-
I’m looking to change my slugs dynamically so that they are displayed with the names of my terms, for that I created an option in the administrator panel that should allow me to start the process, but I do not really know where to start.
For starters I think I’ll have to recover the taxonomies in which I find all the terms that I will have to dynamically change.
Would someone have a sample code that I could exploit for this function that i’m trying to create?
here are the taxonomies in which I will have to go to get my terms to modify these dynamically::
Taxonomies: recipe_category, recipe_type, recipe_event, product_category
here’s the code that will allow me to start the process:
<?php add_action( 'admin_menu', 'slug_migrate_menu' ); function slug_migrate_menu() { add_submenu_page('edit.php?post_type=recipe', 'Migration des slugs', 'Migration des slugs', 'manage_options', 'slug-migrate', 'slug_migrate_page'); } function slug_migrate_page() { ?> <h1>Migration des slugs</h1> <button id="migrateSlugBtn">Go !</button> <div id="migrateSlugResult"></div> <script> jQuery('#migrateSlugBtn').click(function(e) { jQuery.post( '<?php echo admin_url( 'admin-ajax.php' ); ?>', { 'action': 'slug_migrate', }, function(response){ jQuery('#migrateSlugResult').append(response); } ); }); </script> <?php } add_action( 'wp_ajax_slug_migrate', 'slug_migrate' ); add_action( 'wp_ajax_nopriv_slug_migrate', 'slug_migrate' ); function slug_migrate( $taxonomy ) { // Taxonomies : recipe_category, recipe_type, recipe_event, product_category // Pour chaque term des taxonomies : Effectuer un sanitize_title() du name du term et l'afficher // begin of code // end of code add_filter( 'editable_slug', 'sanitize_slug' ); die(); }
- The topic ‘I want to change the slugs of my terms dynamically’ is closed to new replies.