Home › Forums › ACF PRO › verify get_field value and redirect to a page › Reply To: verify get_field value and redirect to a page
Hi @venkatesham
So to build on @felipeost answer with a real functional example using WordPress functionality. You should be able to paste this into your themes functions.php and just change the ID numbers (1 and 2) to the correct ones for your pages.
function my_custom_redirect(){
global $post;
$model_name = get_field( 'model_name', $post->ID );
switch ($model_name) {
case 'iphone':
$redirect = get_permalink(1); // Change 1 to the ID of your iphone page
wp_redirect($redirect);
exit();
break;
case 'samsung':
$redirect = get_permalink(2); // Change 2 to the ID of your samsung page
wp_redirect($redirect);
exit();
break;
}
}
add_action( 'template_redirect', 'my_custom_redirect' );
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.