Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created August 1, 2013 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remcotolsma/6131041 to your computer and use it in GitHub Desktop.
Save remcotolsma/6131041 to your computer and use it in GitHub Desktop.
Insert WordPress redirection items for the Redirection plugin (http://wordpress.org/plugins/redirection/) from WordPress post meta imported URL.
INSERT
INTO wp_redirection_items (
url ,
group_id ,
action_type ,
action_code ,
action_data ,
match_type
)
SELECT
REPLACE( REPLACE(meta.meta_value, 'http://www.example.com', ''), 'http://example.com', '') AS url ,
3 AS group_id ,
'url' AS action_type ,
'301' AS action_code ,
CONCAT( 'http://www.example.com/?p=', post.id ) AS action_data ,
'url' AS match_type
FROM
wp_posts AS post
RIGHT JOIN
wp_postmeta AS meta
ON
post.ID = meta.post_id
AND
meta.meta_key = '_import_url'
WHERE
post.guid != '';
@zogot
Copy link

zogot commented Aug 1, 2013

👍

@remcotolsma
Copy link
Author

INSERT
    INTO wp_redirection_items (
        url ,
        group_id ,
        action_type ,
        action_code ,
        action_data ,
        match_type
    )
SELECT
    REPLACE( REPLACE(meta.meta_value, 'http://www.metaalmagazine.nl', ''), 'http://metaalmagazine.nl', '') AS url ,
    3 AS group_id ,
    'url' AS action_type ,
    '301' AS action_code ,
    CONCAT( 'http://www.metaalmagazine.nl/?p=', CAST( post.id AS CHAR(20) ) ) AS action_data ,
    'url' AS match_type
FROM
    wp_posts AS post
        RIGHT JOIN
    wp_postmeta AS meta
        ON
            post.ID = meta.post_id
                AND
            meta.meta_key = '_import_url'
        WHERE
            post.guid != '';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment