CPT – Nice url with add_rewrite_rule

Question

I read lot of topick, but it don’t work. And I really don’t know what i do wrong …

I put this code the the fonction.php of my child theme :

       <?php 
function add_rewrite_url() {
    
    add_rewrite_tag( '%property_status%','([^&]+)' );
    add_rewrite_tag( '%property_city%','([^&]+)' );
    add_rewrite_tag( '%property_area%' ,'([^&]+)' );
    
    add_rewrite_rule(
    // l'URL site.com/annonce/location/nosy-be/ambatoloaka/ample-apartment/'
      'property/([^/]+)/([^/]+)/([^/]+)',
    // Devient index.php?post_type=property&region=property_status&ville=property_city&quartier=property_area
      'index.php?post_type=property&property_status=$matches[1]&property_city=$matches[2]&property_area=$matches[3]',
      'top'
    );
}
add_action( 'init', 'add_rewrite_url' ); 

I don’t dorget to update /wp-admin/options-permalink.php"

Nothink change …

any idea what I’m forgetting?

thnaks for your help !

0
Antonin Auvray 8 months 2020-11-30T08:10:32-05:00 0 Answers 11 views 0

Leave an answer

Browse
Browse