WordPress.org

Forums

WordPress MU Sitewide Tags Pages
[resolved] Post Meta not Saving to Tags Blog (10 posts)

  1. stoi2m1
    Member
    Posted 3 years ago #

    I have built a custom post type for saving music with a post. I have built a custom interface and uploader to allow members of my network to upload music they have created to their blogs. With this custom interface and uploader a post is created and post_meta (custom fields) are saved.

    The issue I have just discovered is the post_meta is not being saved to the tags blog.

    I am using have 3 steps to creating the custom post:

    $postid = wp_insert_post($my_post);
    wp_set_object_terms( $postid, $atags, 'post_tag', false );
    update_post_meta($postid, 'genre', $genre);
    update_post_meta($postid, 'subgenre', $subgenre);
    update_post_meta($postid, 'trackurl', $url);

    Those are just a few of the custom fields being created. But none of them are making there way over to the tags blog. Im thinking I could trigger a post update of the just created $postid.

    Is there a better or more WordPress way of either creating the post so that the post_meta is imported to the tags blog? Maybe I can add an additional hook within the plugin so it catches when post_meta is updated as well?

    Thanks,
    Jesse

    http://wordpress.org/extend/plugins/wordpress-mu-sitewide-tags/

  2. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    Does the post come through to the tags blog?

    Did you add those custom fields to the post meta list in the SWT settings?

  3. stoi2m1
    Member
    Posted 3 years ago #

    Yes I have all the custom fields in the settings, they all imported in with no issue.

    Yes the post saves to the tags blog it just missing all of the custom fields.

  4. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    Are you looking for them in the edit post area or on the front of the site?

  5. stoi2m1
    Member
    Posted 3 years ago #

    I was looking directly in the database. At the post_meta table.

  6. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    Looking at your code above

    $postid = wp_insert_post($my_post); // <-- SWT copies the post to the tags blog inside of this function call
    wp_set_object_terms( $postid, $atags, 'post_tag', false );
    update_post_meta($postid, 'genre', $genre);
    update_post_meta($postid, 'subgenre', $subgenre);
    update_post_meta($postid, 'trackurl', $url);
  7. stoi2m1
    Member
    Posted 3 years ago #

    Do you have any suggestions for me? I tried addind a wp_update_post function at the end of my post creation, but that didnt seem to work.

    Should I add some custom code into the SWT plugin to hook in the saving of tags and postmeta?

  8. stoi2m1
    Member
    Posted 3 years ago #

    I have tried the following code to add a post update action which I was hoping would trigger the save_post hook.
    '
    $postid = wp_insert_post($my_post);
    wp_set_object_terms( $postid, $atags, 'post_tag', false );
    update_post_meta($postid, 'genre', $genre);
    update_post_meta($postid, 'subgenre', $subgenre);
    update_post_meta($postid, 'trackurl', $url);
    $mypost['ID'] = $postid;
    wp_update_post($my_post);
    '

    This didnt work. What I have found works is viewing the custom post/track in the custom editor I wrote and saving it.

    Im using wp_update_post to update the post/track in my custom editor. So I dont understand why that doesnt work when I use it during my post creation.

  9. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

    Try setting the post status to draft in the first save and change it to publish before you update.

  10. stoi2m1
    Member
    Posted 3 years ago #

    Its now working.

    Thanks for the tip. I was actually misspelling my post ID variable so that was the source for the wp_update_post not working, but going from draft to published makes since here. I didnt discover it until I went in to edit the post_status.

    Thanks again for your time and help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic