• Resolved ElwoodP

    (@elwoodp)


    Is it possible to create “duplication links” automatically when using batch duplication?

    • This topic was modified 8 years ago by ElwoodP.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author MagicStick

    (@magicstick)

    Not out the box. Gimme an hour to get home and I’ll shoot over some code for you to implement.

    Thread Starter ElwoodP

    (@elwoodp)

    Amazing, thanks so much.

    Plugin Author MagicStick

    (@magicstick)

    Hey ElwoodP add the following code to your functions.php in your theme and any post duplicated in batch mode will be linked:

    if(function_exists('mpd_duplicate_over_multisite')){
    function mpd_auto_link_on_batch($batched = null){
    
        if($batched){
    
            $batched_ids = get_option('mpd_batch_ids');
            $index = 0;
            
            foreach($batched as $duped_post_details){
    
                $args = array(
    
                    'source_id'         => get_current_blog_id(), 
                    'destination_id'    => $batched_ids[$index][1],
                    'source_post_id'    => $batched_ids[$index][0],
                    'destination_post_id' => $duped_post_details['id'],
    
                );
    
                mpd_add_persist($args);
    
                $index++;
    
            }
    
        }
        delete_option('mpd_batch_ids');
        
    }
    
    add_action('mpd_batch_after', 'mpd_auto_link_on_batch', 100);
    
    function mpd_record_batch_source_id($post_id, $blog_id){
    
        $batched_ids = get_option('mpd_batch_ids');
    
        if($batched_ids){
            $batched_ids[]  = array($post_id, $blog_id);
        }else{
            $batched_ids    = array(array($post_id,$blog_id));
        }
        update_option('mpd_batch_ids', $batched_ids);
    
    }
    
    add_action('mpd_single_batch_before', 'mpd_record_batch_source_id', 20, 2);
    }
    Thread Starter ElwoodP

    (@elwoodp)

    Works perfectly, thanks!

    Seems like a useful thing to be able to do, maybe could be added as an option in a future release?

    • This reply was modified 8 years ago by ElwoodP.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Create post link with batch dupication’ is closed to new replies.