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