Adding dropdown select meta box to custom post type – seems restAPI is interfering


I have a custom post type, call it topic. It is from BBPress, but this isn’t a BBPress question.

I also have a post type lessontopic.

I added a meta box to BBPress so that I can choose an associated Lesson Topic for the Forum Topic when I am in the BBPress Topic backend editor, and that save that as post meta data.

Here is what I did:

add_action( 'add_meta_boxes', 'ld_bbpress_display_ldtopic_selector');

function ld_bbpress_display_ldtopic_selector() {
    add_meta_box( 'ld_bbpress_ldtopic_selector', __( 'LearnDash bbPress Settings', 'learndash-bbpress' ), 'ld_bbpress_display_topic_selector_callback', 'topic', 'advanced', 'high' );

function ld_bbpress_display_topic_selector_callback() {
   My call back stuff

add_action( 'save_post_topic', 'ld_save_associated_ldtopic',10,1);
function ld_save_associated_ldtopic($topic_id){
    if ( ! wp_verify_nonce( $_POST['ld_bbpress_nonce_ldtopic'], 'ld_bbpress_meta_box_ldtopic' ) ) {
    my save stuff

Now everything looks ok in backend. But if I choose a lesson topic from my meta dropdown, and hit update, and step through in my debugger, I see that the update is performed in


This has to do with the fact that for a custom block I made that enables me to select forum topics, I had to enable BBPress topics to be seen in restAPI, and that mysteriously causes backend editor to hit the restAPI endpoint for updates. I did that restAPI enabling via

add_filter( 'bbp_register_topic_post_type', 'enable_restAPI_bbpress_topics', 10,1);
function enable_restAPI_bbpress_topics ($args) {
    $args['show_in_rest'] = true;
    $args['supports'] = array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' );
    return $args;

But I don’t understand: why does the mere act of checking off that a post type is visible to restAPI cause wordpress’s backend editor to go into a completely different mode of operation? I mean, we are talking about backend. If I enable restAPI, I can see how that should facilitate headless CMS, etc, but why on earth does it so radically alter how WordPress deals with backend post editing?

Somehow, this is resulting in my save hook ld_save_associated_ldtopic not seeing the $_POST array and therefore not seeing nonce data.

Really quite peculiar. I feel like I am breaking some rule and it is biting me, but not sure what I need to do to get my meta box to work in this fashion.



, , , Brian 3 years 2019-12-04T06:17:34-05:00 0 Answers 114 views 0

Leave an answer