PHP Redirect Script Not Working
-
Hi,
I am working on a script to redirect a WordPress post to a new site. I’m moving an individual WordPress blog to a WordPress network. On the network site the permalink structure is changing like this:
Old Permalink: https://www.example.com/YYYY/MM/the-permalink-link.html/
New Permalink: https://www.newdomain.com/example/YYYY/MM/DD/the-permalink-link/
The script I’m running will grab the post date and break it up so I can get the DD. I’m running it before the open <html> tag. Here is the script:
<?php $post_obj = $wp_query->get_queried_object(); $post_ID = $post_obj->ID; $post_title = $post_obj->post_title; $post_slug = $post_obj->post_name; $post_date = $wpdp->get_results("SELECT post_date FROM wp_posts WHERE post_title = '$post_slug'"); list($y, $m, $d) = explode('-', substr($post_date, 0, 9)); $new_url = 'https://www.rantsports.com/TEAM-NAME/'.$y.'/'.$m.'/'.$d.'/'.$post_slug.'/'; Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: ".$new_url."" ); ?>
And I’m getting the following error:
Fatal error: Call to a member function get_results() on a non-object in /home/letsgetm/public_html/wp-content/themes/lgm_rantsports/single.php on line 8
Thanks,
Grant
- The topic ‘PHP Redirect Script Not Working’ is closed to new replies.