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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.