Forum Moderators: coopster

Message Too Old, No Replies

php redirect script

         

gbrown442

6:18 am on Jul 28, 2011 (gmt 0)

10+ Year Member



Hi, I'm running the following script on a WordPress blog that has changed domains to do a 301 Redirect to the new spot. Here's the code:

<?php

define( 'BLOCK_LOAD', true );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.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 = $wpdb->get_results("SELECT post_date FROM $wpdb->posts WHERE post_name = '$post_slug'");

list($y, $m, $d) = explode('-', substr($post_date, 0, 9));

$new_url = 'http://www.example.com/TEAM-NAME/'.$y.'/'.$m.'/'.$d.'/'.$post_slug.'/';

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: ".$new_url."" );

?>


And its outputting to:

http://www.example.com/TEAM-NAME/Array/team-usa-has-alot-to-look-forward-too/

Thanks

gbrown442

7:45 am on Jul 28, 2011 (gmt 0)

10+ Year Member



Fixed. Added this after DB query:

foreach($post_date as $post_day) {
$postted_date = $post_day->post_date;
}

penders

2:51 pm on Jul 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



foreach($post_date as $post_day) {  
$postted_date = $post_day->post_date;
}


This does look very strange! I assume your result only contains 1 row? May be you should be calling get_row() instead of ge_results() ?

gbrown442

3:14 pm on Jul 28, 2011 (gmt 0)

10+ Year Member



It does only contain 1 row, didn't think about that.

Thanks