Support

Account

Home Forums ACF PRO Add a custom field to custom type permalink Reply To: Add a custom field to custom type permalink

  • Thank a lot John for your answer,

    I’m making slow progress on this rewrite.
    but I can’t put the value of my field in my rewrite rule

    I want a permalink like this example : https://www.domain.com/annoncelegale/L010422

    There is the code :

    // Custom URL Rewrite with Parameter on WordPress for Legal Notices with reference
    add_filter('query_vars', 'annonce_legale_custom_query_var');
    function annonce_legale_custom_query_var($vars) {
    	$vars[] = 'ref_acf';
    	return $vars;
    }
    
    // Defining the rewrite rule for Legal Announcements
    add_action('init', 'annonce_legale_add_rewrite_rule');
    function annonce_legale_add_rewrite_rule() { 
    	add_rewrite_rule(
            'annonces-legales/([^/]+)/?', 
            'index.php?post_type=annoncelegale&ref_acf=$matches[1]',
            'top'
        );
    }

    How can I attribute ref_acf to the ACF field ?
    <?php the_field( ‘reference_al’ ); ?>

    In advance, thank you for your help.