The MU forums have moved to WordPress.org

add_post_meta() across blogs? (6 posts)

  1. mdgross
    Member
    Posted 16 years ago #

    Let's say you're in blog 75 and you want to add_post_meta() to a post in blog 36.

    Is this possible? Thanks!

  2. andrea_r
    Moderator
    Posted 16 years ago #

    Uh, no. And if it was it'd be a huge freaking security nightmare.

    You may own all the blogs on your system, but on a regular WPMU setup, each blog is individually owned and administered.

  3. mdgross
    Member
    Posted 16 years ago #

    We're using Donncha's sitewide plugin to aggregate posts from all blogs into a single WordPress blog. The problem is it doesn't copy the post meta.

    Our template looks for the post meta topstory=yes to populate the main post. I have a button that only shows up for certain staff members who have passed a security check. (Seriously, security is not an issue here...) Now that this button shows up on every blog... short of manually creating the SQL code is there a better API solution?

  4. andrea_r
    Moderator
    Posted 16 years ago #

    I'd alter the plugin to pull the post meta as well. Probably the simplest way.

    See, in your initial question, it reads like you're asking how to do this while writing a post. :)

  5. mdgross
    Member
    Posted 16 years ago #

    Ok all context aside....

    Basically I need to create this function in PHP... a slightly adapted version of the original add_post_meta() in WordPress

    <?php add_post_meta_to_blog($post_id, $blog_id, $meta_key, $meta_value, $unique); ?>

  6. mdgross
    Member
    Posted 16 years ago #

    function add_post_meta_to_blog($blog_id, $post_id, $meta_key, $meta_value, $unique)
    {
    	switch_to_blog($blog_id);
    	add_post_meta($post_id, $meta_key, $meta_value, $unique);
    	restore_current_blog();
    }

    look good?

About this Topic