Form Hooks/Filters for multisite CPT conditional switching situation?

Support MB Frontend Submission Form Hooks/Filters for multisite CPT conditional switching situation?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #10601
    DanDan
    Participant

    Hi Anh-

    Situation: Multisite where I am redirecting posts based on their content to CPTs on these various subdirectories. So if they chose "apple" it would be redirected to the fruit CPT.

    What I know I could do:

    add_action( 'rwmb_frontend_before_process', function( $config, $post_id ) {
        if ('my-meta-boxes' == $config['id']){
            if($field['category'] = 'apples'){
                switch_to_blog(8);
                post->post_type = 'fruit';
            }
            if ($field['category'] = 'drums'){
                switch_to_blog(9);
                $post->post_type = 'instruments';
            }
            // then I do all the wp_insert_post stuff because if I restore_current_blog() before that, then it won't save to those CPTs.
        }
    }, 10,2 );

    Why I don't want to do this: I don't want to jump into the post save cycle you've set up with Meta Box. I want to be able to switch blogs like above, but have Meta Box save before I then switch back.

    Any suggestions? thank you!

    #10602
    DanDan
    Participant

    quick update on the above- it actually doesn't save to the CPTs of the subdirectory, just the basic post type. Interesting. Looks like I'll need to manually wp_insert_post them.

    #10612
    Anh TranAnh Tran
    Keymaster

    Hi Dan,

    I'm not really clear about this issue. Can you explain what you're trying to do?

    #10613
    DanDan
    Participant

    Sure- so since my website is going to be very data heavy, I made a decision to strategically parse custom posts into multiple custom post SQL tables, which I've done through created a multisite with subdirectories. It works well in testing, using switch_to_blog and so on. Basically a long-term decision based on application.

    So:
    Step 1 - User enters data in a centralized form which will become a CPT. However which specific CPT is unknown until they say what type of "x" it is.
    Step 2- The submitted post is quickly hooked (like I've done before). Which CPT is ends up at is based on the user's selection.

    Normally I could do my previous code and it would just save to the right CPT. However with what I'm doing here, I have to keep it in whatever blog has the CPT until it is saved, and then "restore_current_blog".

    I can manually hook it and save each type with wp_insert_post and then restore_to_blog, but I was trying to avoid that.

    So, in summary, Post written --> Hooked before save -->CPT determined and sent to the right blog (subdirectory)-->saved --> restore_to_current_blog

    Hope that cleared things up. I know it is a very unique set of requirements, and I don't anticipate something that will work other than me wp_inserting myself. thanks!

    #10616
    Anh TranAnh Tran
    Keymaster

    I got it (partly). I think hooking into the rwmb_frontend_before_process couldn't solve the problem, because this hook has only info about the current form, not the post.

    Can you try using the filters rwmb_frontend_insert_post_data / rwmb_frontend_update_post_data (docs here)? It might help modifying the post type before submitting to the DB.

    However, I'm not sure about the switch blog part. It sounds complicated.

    #10618
    DanDan
    Participant

    yeah the switch blog part is the kicker. Simply switching between CPTs in the same subdirectory is easy (as long as it is the initial insert post). I know it can be done (I'm doing it now), just not on the scale I'm describing here. I'll look at your suggestions, but it'll be fine either way. thanks

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Form Hooks/Filters for multisite CPT conditional switching situation?’ is closed to new replies.