From a7a663fc2f98b56f6d99d22f65aca2ec6e1529e3 Mon Sep 17 00:00:00 2001 From: Stefan Bohacek Date: Thu, 10 May 2018 21:06:28 -0400 Subject: [PATCH] For external resources, redirect post page to external URL. --- includes/post-types/resources.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/includes/post-types/resources.php b/includes/post-types/resources.php index f1b77f8..81fc6fa 100644 --- a/includes/post-types/resources.php +++ b/includes/post-types/resources.php @@ -8,6 +8,8 @@ function post_type_setup() { add_action( 'save_post', array( $this, 'save_meta' ), 10, 2 ); add_filter( 'enter_title_here', array( $this, 'change_post_title_placeholder' ) ); add_filter( 'post_type_link', array( $this, 'resource_page_link' ), 1, 3 ); + add_filter( 'template_redirect', array( $this, 'external_resource_redirect' ) ); + } function create_post_type() { @@ -15,6 +17,16 @@ function create_post_type() { add_action( 'init', array( $this, 'register_resource_type_taxonomy' ), 40 ); } + function external_resource_redirect() { + global $wp_query; + if ($wp_query->query['post_type'] === 'resource'){ + $external_resource_url = get_post_meta( $wp_query->posts[0]->ID, 'resource_url', true ); + if ( !empty( $external_resource_url ) ){ + wp_redirect( $external_resource_url ); + } + } + } + function resource_page_link( $post_link, $post ){ $post = get_post($post->ID); $post_type = get_post_type( $post->ID );