Home › Forums › General Issues › Redirect to File URL › Reply To: Redirect to File URL
Hi Andrew,
Thanks for your help regardless of the confusion.
We’re close! I’m using a Snippets plug-in to insert the PHP to the header of these specific Custom Post Types we don’t have to solve that.
Therefore, I was really looking for that second part which Checks if the URL is not empty and Performs the redirect. The
<?php> function redirect_to_acf_file_url() {
// 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');
?>
I changed my own Field Name to file_url to match the code. Just to clarify, the Field on ACF is in fact a File field, these files are usually PDF.
When the Resource post is accessed, we want them to bypass the post, straight into the URL of PDF file within the post, seclected through ACF.
Let me know if there’s any more clarification needed.
Thanks!
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.