Advertisement
miriamdepaula

WordPress: Custom Field URL parameter

Jul 30th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. <?php
  2. //in the functions.php
  3.  
  4. add_action('parse_request','oldsite_redirect',0);  // 0=before (most) 'parse_request' calls
  5. function oldsite_redirect() {
  6.   if (isset($_GET['lid'])) {
  7.     global $wpdb;
  8.     $sql = "SELECT post_id FROM {$wpdb->postmeta} " .
  9.            "WHERE meta_key='lid' AND meta_value='%s'";
  10.     $sql = $wpdb->prepare($sql,$_GET['lid']);
  11.     $post_id = $wpdb->get_var($sql);
  12.     if ($post_id) {
  13.       $permalink = get_permalink($post_id);
  14.       if ($permalink) {
  15.         wp_safe_redirect($permalink,301);
  16.         exit;
  17.       }
  18.     }
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement