Support

Account

Home Forums General Issues Redirect to File URL Reply To: Redirect to File URL

  • I am a bit confused by the question, is this sort of what your going for?

    function redirect_to_acf_file_url() {
        // Check if it is a singular "Resources" post
        if (is_singular('resources')) {
            // Get the current post ID
            $post_id = get_the_ID();
    
            // Get the URL from the ACF file field, assuming the field name is 'file_url'
            $file_url = get_field('file_url', $post_id);
    
            // Check if the URL is not empty
            if (!empty($file_url)) {
                // Perform the redirect
                wp_redirect($file_url, 301);
                exit;
            }
        }
    }
    
    add_action('template_redirect', 'redirect_to_acf_file_url');