Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Aug 1, 2013

👍

@remcotolsma

This comment has been minimized.

Copy link
Owner Author

commented Mar 4, 2014

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
You can’t perform that action at this time.