Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to reformulate a function (in a plugin) so that it applies to posts in a custom post type rather than normal posts.

 function saving_posts($post_id)
    global $wpdb, $user_ID;
    if('post' == $_POST['post_type'])
        if(!current_user_can('edit_post', $post_id))
    $mydata = ($_POST['mf_post_to_forum'] == 'true')?true:false;
        $date = $this->wpf_current_time_fixed('mysql', 0);
        $fid = (int)$_POST['mf_post_to_forum_forum'];
        $_POST['mf_post_to_forum'] = 'false'; //Eternal loop if this isn't set to false
        $post = get_post($post_id);
        $sql_thread = "INSERT INTO {$this->t_threads} (last_post, subject, parent_id, `date`, status, starter) VALUES('{$date}', '".$this->strip_single_quote($post->post_title)."', '{$fid}', '{$date}', 'open', '{$user_ID}')";
        $tid = $wpdb->insert_id;
        $sql_post = "INSERT INTO {$this->t_posts} (text, parent_id, `date`, author_id, subject) VALUES('".$this->input_filter($wpdb->escape($post->post_content))."', '{$tid}', '{$date}', '{$user_ID}', '".$this->strip_single_quote($post->post_title)."')";
        $new = $post->post_content."\n".'<p><a href="'.$this->get_threadlink($tid).'">'.__("Join the Forum discussion on this post", "mingleforum").'</a></p>';
        $post->post_content = $new;

I assumed I could just change if('post' == $_POST['post_type']) to if('my_custom_post' == $_POST['post_type']) and the rest would work the same. The $mydatavalue comes from here:

function send_wp_posts_to_forum()
    add_meta_box('mf_posts_to_forum', __('Mingle Forum Post Options', 'mingleforum'), array(&$this, 'show_meta_box_options'), 'my_custom_post');
function show_meta_box_options()
    $forums = $this->get_forums();
    echo '<input type="checkbox" name="mf_post_to_forum" value="true" />&nbsp;'.__('Add this post to', 'mingleforum');
    echo '&nbsp;<select name="mf_post_to_forum_forum">';
    foreach($forums as $f)
        echo '<option value="'.$f->id.'">'.$f->name.'</option>';
    echo '</select><br/><small>'.__('Do not check this if this post has already been linked to the forum!', 'mingleforum').'</small>';

which works fine as the meta box is present in the right place.

share|improve this question
What is the problem? get_post() does work for custom post types as far as I know since it works of of ID number. No mention in the codex otherwise. –  helgatheviking Jul 16 '13 at 13:42
"I assumed I could just change if('post' == $_POST['post_type']) to if('custom_post_type' == $_POST['post_type']) and the rest would work the same." -- That will only work if your custom post type is named custom_post_type. If you've called it book, for example, then you'd need if ( 'book' == $_POST['post_type'] ) instead. –  Pat J Jul 16 '13 at 13:52
I just called it custom_post_type for the sake of the example. I just cant figure out why it won't won't work with the custom post yet it works fine with the post. It is actually called match_report. –  mantis Jul 16 '13 at 14:15
get_post works fine with a CPT. I just tested it. Please try to locate exactly where the failure occurs. Put var_dump('something'); die; in the callback and work out which one of those if conditionals (I am guessing) is causing the problem. –  s_ha_dum Jul 16 '13 at 14:37
I think the problem is with the meta box on the custom post type admin page. The value (checked) isn't saving when I update the post. –  mantis Jul 16 '13 at 15:25

1 Answer 1

The problem was with $this->setup_links(); which used add_action("publish_post", array(&$this, "saving_posts")); instead of add_action("save_post", array(&$this, "saving_posts"));

Apparently publish_post doesn't work with custom post types.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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