• Resolved Johan

    (@datar)


    Hello!

    Thanks for a great plugin. I have just donated and plan to continue doing so from time to time. πŸ™‚

    My question is if it’s possible to set linked posts from published to draft? If I set “draft” in the main post, the linked post is not updated, which means that i have to set them to draft manually.

    If I delete the main post, linked post will not be deleted. Is this possible to fix? Now I have to delete them manually.

    Thanks for the help!

    Kind regards
    Johan Linnarsson

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author MagicStick

    (@magicstick)

    Hi Johan. Thank you for your info (and for your donation! :-)). I’ll def look to add this functionality in a future release.

    Plugin Author MagicStick

    (@magicstick)

    Hi Johan. I’ll be releasing a fix for your linked post status issue mentioned above later tonight. πŸ™‚

    I’ve had a think about your ‘delete linked post’ request. I have some reservations about putting this into the core without giving the user some options on this so I’m going to have a further think about how to manage this. However if you wish to implement this functionality simply add the following code into your functions.php file in your theme πŸ™‚

    function mpd_trash_linked_posts($post_id){
        
       if (function_exists('mpd_get_persists_for_post')) {
          
           $linked =  mpd_get_persists_for_post(get_current_blog_id(), $post_id);
    
           foreach ($linked as $linked_post) {
               switch_to_blog($linked_post['destination_id']);
                    wp_trash_post( $linked_post['destination_post_id']  );
               restore_current_blog();
           }
        
        }
    
    }
    
    add_action('trash_post', 'mpd_trash_linked_posts');

    Thank you MagicStick. I’ll test it tomorrow and Let you know how the code works. Cheers πŸ™‚

    I think it would be an awesome feature to add the posibilities to delete posts or change poststatus. I understand that it needs som thinking and take your time on this.

    Btw I’m going to translate it to Swedish. πŸ™‚

    Hello MagicStick.

    Tried your code now. It seems to work nearly perfect. When I change poststatus, everything works great. But when I try to delete I get the following:

    Fatal error: Cannot use object of type stdClass as array in /home/xxx/public_html/wp-content/themes/mytheme/functions.php on line 83

    It’s still a great start. Any suggestions how to fix this? Line 83 is this piece of code:
    switch_to_blog($linked_post[‘destination_id’]);

    The post is deleted from the main site despite the error, but on the other sites the post is published to, the post remains intact and is not deleted.

    Thanks for all the help.

    Kind regards
    Johan πŸ™‚

    Plugin Author MagicStick

    (@magicstick)

    My bad. This should work:

    function mpd_trash_linked_posts($post_id){
        
       if (function_exists('mpd_get_persists_for_post')) {
          
           $linked =  mpd_get_persists_for_post(get_current_blog_id(), $post_id);
    
           foreach ($linked as $linked_post) {
               switch_to_blog($linked_post->destination_id);
                    wp_trash_post( $linked_post->destination_post_id  );
               restore_current_blog();
           }
        
        }
    
    }
    
    add_action('trash_post', 'mpd_trash_linked_posts');

    Thank you MagicStick. That works perfectly. For your notice (it’s not an issue for me) when a post or page is deleted linked post is deleted as well. So far soo good. When you permanently delete a post, it will not be permanently deleted on the other multisite blogs.

    No issue for me, but just want to inform you about this πŸ™‚

    All the best to you!

    Regards
    Johan

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Update post status on linked posts?’ is closed to new replies.