Support

Account

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' );