WordPress.org

Ready to get started?Download WordPress

Forums

Allowing Blog/Site to Clone Individual Post From Main Blog/Site (4 posts)

  1. kirkward
    Member
    Posted 1 year ago #

    I have a multisite network installed, activated and operating properly.

    On this site, I use Andrea and Ron Rennick's site replicator plugin to create new blogs or sites. The plugin operates flawlessly. I also use a plugin called Restrict Categories which allows me to prevent site admins from accessing the posts in specific categories. This plug also works as described.

    On home page of each site in the network, I have a section where thumbnail images for four posts are shown. These posts are set up as sales pages designed to sell products that I develop. I pay each site admin a commission for sales of any of the four featured products from their website. By using the site replicator, I am able to ensure that these four thumbnails are on a page with a consistent look and feel and in the same position on each site.

    On my main site, I have a large inventory of product posts and I am constantly developing new posts or sales pages to promote new products.

    I want to give the site admins the ability to select the product posts or sales pages they wish to feature on their site. I also do not want them to overwhelm their site with a bunch of product pages, and I don't want to impose any more than the four that the page was designed to highlight. That's where the Restrict Categories plugin comes in. It keeps them from fiddling with the sales pages or posts.

    The only thought I have been able to come up with is to develop an admin dashboard widget for each of the four thumbnail image positions, and encode a method for the site admin to select a product from a drop down list of all the posts in my product category, and then have that post cloned to their site, replacing the previous post featured in that position.

    The cloned post will have three option fields which the local site admin will be able to edit, providing some personalization for their sites copy of the sales page.

    Can anyone suggest a method for accomplishing this?

    Possibly a plugin, possibly a custom set of functions reading the post from the main blog/site and updating the existing post on the current site?

    I am a VERY neophyte coder, working mainly within the CPET model (copy, paste, edit and test). I'm also very weak in the understanding of hooks, actions, callbacks and functions. I get the idea of functions, they are basically small snippets of code, or mini-scripts. The others lose me.

    I'll try almost any idea you can throw at me, and I will post the completed or working code product here when it is completed, if you want it.

    Thanks, many thanks in advance.

  2. kirkward
    Member
    Posted 1 year ago #

    I started thinking through my description ... here are some functions that I thought of, and an order I started putting them in.

    Anyone have suggestions on a streamlined way to turn it into something useful>

    /***********************************************/
    /* To switch to another blog */
    /***********************************************/
    
    <?php
        global $switched;
        switch_to_blog($main_cat_id);
        echo 'You switched from blog ' . $switched . ' to ' . $main_cat_id ;
    ?> 
    
    /***********************************************/
    /* To get the category ID by Name */
    /***********************************************/
    
    <?php $main_cat_id = get_cat_ID( $cat_name ) ?> 
    
    /***********************************************/
    /* To get a list of post from a category */
    /* Place this code before the restore_current_blog() above */
    /***********************************************/
    
    //
    // Edit the action below so that the selected item is saved to an array
    //
    
    <form action="<? bloginfo('url'); ?>" method="get">
     <select name="page_id" id="page_id">
    <?php
     global $post;
     $args = array( 'numberposts' => -1, 'category' => $main_cat_id,);
     $posts = get_posts($args);
     foreach( $posts as $post ) : setup_postdata($post); ?>
                    <option value="<? echo $post->ID; ?>"><?php the_title(); ?></option>
    <?php endforeach; ?>
     </select>
     <input type="submit" name="submit" value="select" />
     </form>
    
    /***********************************************/
    /* To switch back to the original blog */
    /***********************************************/
    
    <?php
        restore_current_blog();
        echo 'You switched back to ' . $switched ;
    ?>
    
    /***********************************************/
    /* Now create some code to save the post object as Special Offer #1, 2, 3 or 4  */
    /***********************************************/
    
    <?php
    // Update post
      $my_post = array();
      $my_post['ID'] = 37;
    
    // Update the post into the database
      wp_update_post( $my_post );
    ?>
    
    /***********************************************/
    /* Memo from a Google search */
    /***********************************************/
    
    The function that calls the pre_post_update hook appears on line 1525 of wp-includes/posts.php for me:
    
    do_action( 'pre_post_update', $post_ID );
    
    As you can see, it passes the ID of the post being updated when it is executed. To get the post from there, you would just call get_post(), e.g.:
    
    function do_something_with_a_post($id) {
         $post = get_post($id);
         // now do something with it
    }
    add_action('pre_post_update', 'do_something_with_a_post');
    
    The $post variable above should reference an object with all of the various attributes about a post you are looking for, hopefully.
  3. squibm
    Member
    Posted 8 months ago #

    Hi Kirkward. Found your post on wordpress.org regarding post cloning.

    I have a similar challenge. Did you find a solution ? If yes - please share what you learned. If no, do you want to collaborate?

    I have a consulting issue that relates to content deployment - where selective deployment from a library, by internal users, is a common need. Limiting my audience to high-value messages is key.

    Thanks,
    squibm

  4. esmi
    Forum Moderator
    Posted 8 months ago #

    @squibm: If you require assistance then, as per the Forum Welcome, please post your own topic.

Topic Closed

This topic has been closed to new replies.

About this Topic