The MU forums have moved to

add postmeta (8 posts)

  1. musnake
    Posted 15 years ago #

    I posted this in a special someone's comment listing but realize that a question turns into a thread...

    I'd like to add/copy some meta data from a $post that is being mirrored in another table. I observed how the $permalink value was set and broke out my rubber stamp... alas.

    $p = wp_insert_post( $post );
    add_post_meta( $p, “permalink”, $permalink );
    // Add some of the custom field post meta,
    // specifically the value of the key ‘thumbnail’
    $myThumb = get_post_custom_values(’thumbnail’, $p);
    if ($myThumb)
    add_post_meta( $p, “thumbnail”, $myThumb );

    Was I supposed to lick the stamp first?

  2. musnake
    Posted 15 years ago #

    Ok, getting there.

    This works...

    // Somewhere appropriate...
    $myThumb = get_post_meta($post_id, "thumbnail", $single = true);
    // skip down to where it makes sense for you...
    // Add some of the custom field post meta,
    // specifically the value of the key "thumbnail"
    // Is a "thumbnail" value being set now?
    if ($myThumb !='') {
            // Did $tags_blog already have a value for "thumbnail"?
    	if (get_post_meta($p,"thumbnail")) {
    		update_post_meta ($p, "thumbnail", $myThumb);}
    	else {
    		add_post_meta( $p, "thumbnail", $myThumb, true );}
    	else {
    		// Did $tags_blog already have a value for "thumbnail"?
    		//  Well, unset it now
    		if (get_post_meta($p,"thumbnail")) {
    			delete_post_meta ($p, "thumbnail");}

    Now I guess the next step is to parse all the postmeta so that that data is available to the plugins as they pull the post info from the mirrored table...

  3. Anonymous
    Posted 15 years ago #

    Hi musnake! Does this help with converting [gallery] tags in the post-text of the origin post to IMG-paths in the text of the target post, created by the 'sitewide tags'-plugin introduced by Donncha?

    I´m not so experienced with MU & php-programming. A hint would be great.

    Kind regards,


  4. musnake
    Posted 15 years ago #


    It's true that I am hacking away at Donncha's sitewide tags plugin.

    I don't use the [gallery] tags but would guess that WPMu resolves the shortcode based on the current blog id? You asking the question indicates that resolving the shortcode on another blog (like the global blog) does not produce the desired results?

    I have the same thing (I suspect) where the thumbnails of attached images are not displayed on the global blog (they are if I use a custom field "thumbnail", hence this thread to figure out how to pull postmeta...).

    One surprising thing that did work, is setting the value of the the 'thumbnail' custom field (cf) key to:

    "worked" just fine on the main blog! WPMu is smart enough to figure out the path to the original blog file repository...

    So, if you can figure out how it does that, you could insert the same process with your gallery tag... Easier said than done for us, I know!

    I bet that if you look at what/where/when the postmeta data related to the gallery shortcode is generated, you'd be able to use one of the postmeta or custom field functions to add that data to the global blog like I added the cf 'thumbnail' stuff above.

    BTW, when I delete an original post, postmeta I added is deleted as part of the core functionality so that's nice...

  5. musnake
    Posted 15 years ago #

    Hey Andreas,

    Image Link:
    Use wp_get_attachment_image() if you want the image only (not a hyperlink).


    Take a look at
    The "Output" section was interesting.

    There was also this:


    After reading some of that stuff, I'm under the impression that the shortcodes would get resolved on the main blog as they are on the subblog. I guess the attachment path is subblog specific? Let me know!

  6. politicalbear
    Posted 15 years ago #

    Ok, please help.

    Question: What do I add to Site Wide Tags plugin to get custom field "Image", and where do I put the code?

    I am trying to do the same thing as musnake, but I am trying to get "Image" custom field.

    So, for testing purposes.....I screwed things up. Just kidding (but not really that is why I still have to ask the question.) I took what he did and instead of trying to change it, I just changed what I was doing and re-labeled my custom field and the what I used to attempt to parse it.

    Monkey see, monkey do

    This didn't work, so in the case I was trying to parse it incorrectly I checked phpmyadmin, and it wasn't there either......which means that I don't understand what MuSnake was doing. (It was in the original post phpMyAdmin table)

  7. politicalbear
    Posted 15 years ago #

    Oh and I believe that the solution is over here, but I tried it as well.....and failed.

    and one clarification: "re-labeled my custom field and the what I used to attempt to parse it."

    I re-labeled it "thumbnail"

  8. politicalbear
    Posted 15 years ago #

    Ok, done spamming myself for awhile.

    I hadn't checked PhpMyAdmin when I last tried to the topic 9741 solution, but I just did and this "a:0:{}" is all that is what am I missing.

About this Topic

  • Started 15 years ago by musnake
  • Latest reply from politicalbear