• Resolved tecladigital

    (@tecladigital)


    Hi!

    I’m using the duplicate_post_clone_post_link on my listing page. It work fine. But I don’t want to redirect the user to the post edit page in backoffice and also I prefer to clone the page maintaining the post status.

    Is it possible to have a duplicate link on the frontend just to duplicate that post? If I could set one redirection URL it was nice.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tecladigital

    (@tecladigital)

    I found part of the solution with this:

    https://developer.yoast.com/duplicate-post/filters-actions/#duplicate_post_post_copy

    I add this code to redirect to one page in the front end after duplicating a page:

    “wp_redirect( “https://proposta.tecladigital.pt/teste/”, 301 );
    exit();”

    But the duplicate get “draft” status instead “published” as id should as a cloned post ??

    Thread Starter tecladigital

    (@tecladigital)

    Solved:

    I add this snipped code:

    /**
     * Performs some actions after copying the post.
     */
    function my_custom_duplicate_post_post_copy($new_post_id) {
    
    	$status = "publish";
        // update event based on status
    	
    	$post= array(
                'ID'            => $new_post_id,
                'post_status'   => $status,
            );
    
            wp_update_post( $post );
    	
    	
    	// Perform some actions after copying the post.
        wp_redirect( "https://myurl.xyz/test/", 301 );
        exit();
    }
    
    add_action( 'duplicate_post_post_copy', 'my_custom_duplicate_post_post_copy' );
    OC WordPress Web Designer

    (@oc-wordpress-web-designer)

    Dude, nice! I’ve been looking for this solution everywhere.

    I changed it to redirect the the new post page that is created.

    /**
    Performs some actions after copying the post.
    */
    function my_custom_duplicate_post_post_copy($new_post_id) {
    $status = "publish"; // Update event based on status $post = array(
    'ID' => $new_post_id,
    'post_status' => $status,
    ); wp_update_post($post); // Perform some actions after copying the post.
    wp_safe_redirect(get_permalink($new_post_id), 301);
    exit();
    }
    
    add_action('duplicate_post_post_copy', 'my_custom_duplicate_post_post_copy');

    I also have a shortcode button on the front end for cloning the current post

    function duplicate_post_link_shortcode($atts) {
        $atts = shortcode_atts(array(
            'text' => __('Clone this post', 'your-theme-text-domain')
        ), $atts);
    
        ob_start();
        if (function_exists('duplicate_post_clone_post_link')) {
            echo duplicate_post_clone_post_link($atts['text']);
        }
        return ob_get_clean();
    }
    add_shortcode('duplicate_post_link', 'duplicate_post_link_shortcode');
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Clone page link on frontend’ is closed to new replies.