Something like this should work-
if( get_post_meta( $post_id, '_surl_post_id', true ) ) {
// we have an old post created here
update_post_meta( get_post_meta( $post_id, '_surl_post_id', true ), '_surl_redirect', get_post_meta( $post_id, 'url', true ) );
return;
}
// Prepare contents
$add_cpt_clone = array(
'post_title' => $post_object->post_title,
'post_status' => 'publish',
'post_type' => 'surl'
);
// Insert the post into the database
$p_id = wp_insert_post( $add_cpt_clone );
// Insert the meta key for redirect
update_post_meta( $p_id, '_surl_redirect', get_post_meta( $post_id, 'url', true ) );
// save the id for future use
update_post_meta( $post_id, '_surl_post_id', $p_id );
// Insert any other meta keys that might be needed
Related Posts:
- Can Not Redirect from Plugin-Registered Admin Page
- WordPress Redirect Not Working – AJAX Callback Response Not Picked Up
- Redirecting thousands of posts that currently have no category in their permalink when changing permalink structure to include category
- Crazy redirect happening with no redirects set up
- redirect to a custom page
- Redirection plugin – how to let the editor access the ‘redirection’ menu?
- SSL redirect loop using WordPress HTTPS Plugin
- Redirection Plugin: Redirect all URLs with a regular expression
- flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404
- Detecting $_GET parameters from any page + Cookie
- How to send “Location” header on plugin form submit event?
- Custom url structure for custom template
- wordpress custom login successful redirect hook
- Can’t access my WP dashboard: fatal error? [closed]
- How to redirect Old Post URL to new Post and keep Old post Comments?
- What’s the _wp_desired_post_slug value for?
- Redirect all blog links from WordPress.com site to new domain
- Redirect to a welcome page after updating plugin
- how can I link to a PlugIn admin-sub-menu page after processing a formular
- How does automatic redirection for the redirection plugin work?
- Changed permalink structure. Need help with redirecting old posts
- Landing Page Redirect Chain | http->https->https www
- How can I check if on specific plugin generated page or child
- Redirection based on location but without affecting search bots
- Page Restriction and Redirect for Particular Levels or user
- how to create site exit messages with destination url displayed
- How to redirect a URL with parameters?
- WordPress Shortcode to get URL Parameters $_GET[‘name’] redirects for no reason at all
- Redirecting a buddyboss profile tab to a different tab if not subscribed to a specific membership
- Redirect already logged in users away from a page to a specific page base on user role
- How to fix the woocommerce – adaranth.com redirection issue [closed]
- wp_redirect() Error in Custom Plugin
- How to use login_redirect with a user capability
- Removing Automatic Redirects Without Plugin
- WordPress 4.3 broke meta redirect (with url params plugin)
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- Mask and Track Outbound Links
- How can I redirect some pages to new subdomain? [closed]
- Add to array, redirect and display
- wp_redirect doen’t work
- Notice: Undefined index: mtral_field_subscriber
- wp_redirect not working on plugin
- Conditional custom redirect
- Making the ‘add to cart’ button redirect to PayPal
- PHP mobile redirect Endless loop
- How to force load a page in plugin?
- wp redirect 301 not working in wordpress page
- Preserve Search engine index while shifting to new Domain
- Redirect plugin after form submit or show errors
- Janrain/Simple Modal under Redirected Domain
- Redirect unloggedin users
- login form should redirect to register page for in 1st login next time it should redirected to home page
- Identify User Language, Redirect to the corresponding page and Save the chosen language as Cookie
- www redirects to another directory in wordpress
- Hidden permalink different from displayed permalink
- redirect to homepage once action is completed
- Display value of the GET parameter in a new URL page
- Redirect to a page while maintaining search query parameters without causing an infinite loop
- Woocommerce redirection if no previous orders
- Can’t add new plugin or themes on a wordpress multisite network from the primary site as administrator. Error: ERR_TOO_MANY_REDIRECTS
- How to update all in-site redirect URLs to destination URLs at once
- Using Shortcode Result In Custom HTML Block (Using Google Sheet JQuery Result As NumScroller data-max)
- Link custom post type to page
- Using mu-plugins on the Genesis Framework
- How to send new visitor to a splash page for only one time in wordpress?
- WordPress Admin login redirect to homepage
- Why is my site still showing insecure icon even if I have SSL certificate?
- Reverse count page view and show on other page
- .htaccess file doesn’t work, with hundred tries
- Identify if the_post hook is being called from the admin post list
- Infinite 301 redirects after definitions in “Redirections” plugin?
- Direct URL to a template via plugin
- How to redirect from plugin page
- Redirect loop when forwarding to mobile site
- Template redirect inside of plugin not redirecting
- How to remove post redirects
- Can’t redirect to previous page after using GET
- Need to change contact email depending where user is from
- Redirect url in plugin to somewhere else?
- How do I to override login redirect on specific pages?
- How to link that “logged in” in “you must be logged in to post a comment” with custom login page on WordPress?
- Simple WordPress function / plugin to redirect a site
- URL Redirect on GoDaddy platform [closed]
- Redirecting to page on form submit – Revue plugin
- how to make wordpress remember my choice
- Page with redirect
- is_plugin_active function doesn’t exist
- Prevent Brute Force Attack
- Check if the front end user is log in or not
- Woocommerce Shipping module available only for type of products [closed]
- Plugin jQuery version VS Theme jQuery version: search for best practice
- Modify the file inside plugin dir – the right way
- custom changes removed after plugin update
- Creating shortcodes in plugin
- JQuery needs to be defined in , but Gravity Forms is defining it in the
- Plugin to manage form submissions on admin panel
- Using permalinks with parameters
- Put folder in theme via plugin
- How to block external download link access if visitor not referred from WP?
- Notifications Bar on home page only