I'm using the plugin Wordpress User Frontend and editing the title and content of a post is nice (I managed to change it so I can edit custom post types), but there's no support for editing custom fields. So I have the following code below (not sure if it's too long to have to put on pastebin):

function wpuf_validate_post_edit_submit() {
    global $userdata;

    $errors = array();

    $title      = trim($_POST['wpuf_post_title']);
    $content    = trim($_POST['wpuf_post_content']);
    $tags       = wpuf_clean_tags($_POST['wpuf_post_tags']);
    $cat        = trim($_POST['cat']);
    $post_location  = trim($_POST['wpuf_post_location']);
    echo $post_location;

    if (empty($title)) {
        $errors[] = "Empty post title";
    } else {
        $title = trim(strip_tags($title));

    if (empty($content)) {
        $errors[] = "Empty post content";
    } else {
        $content = trim($content);

    if (!empty($tags)) {
        $tags = explode(',', $tags);

    if (!$errors) {
        $post_update = array(
                'ID'            => trim($_POST['post_id']),
                'post_title'    => $title,
                'post_content'  => $content,
                'post_category' => array($cat),
                'tags_input'    => $tags
        $post_cf = update_post_meta($post->ID,'location',$post_location);
        $post_id = wp_update_post($post_update);

        if ($post_id && $post_cf) {
            echo '<div class="success">Post updated succesfully.</div>';

    } else {
        echo wpuf_error_msg($errors);

$post_cf should update the location field that is grabbed from the top of the code ($post_location). Upon echoing the field, it echo's the updated field, but when saving the post ($post_id?) and refreshing the page, the custom field stays the same?

Does anyone know what's going on? I've been at this for over an hour now.


this line:

$post_cf = update_post_meta($post->ID,'location',$post_location);

$post->ID isn't set in this context, you want to pass $_POST['post_id'] I assume.

  • aha. that did it. Just so I know for future use, could I technically pass $post to the function and THEN use $post->ID? – Josh Allen Aug 24 '11 at 20:14

I'm trying to do the same thing as you with no luck. Did you have to make other changes to the wpuf-edit-post.php for the custom input fields to show up? I'm not a coder so this may seem like a dumb question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.