Form Hooks/Filters for multisite CPT conditional switching situation?
Support › MB Frontend Submission › Form Hooks/Filters for multisite CPT conditional switching situation?
- This topic has 5 replies, 2 voices, and was last updated 6 years, 9 months ago by
Dan.
-
AuthorPosts
-
July 17, 2018 at 9:54 PM #10601
Dan
ParticipantHi 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!
July 17, 2018 at 10:29 PM #10602Dan
Participantquick 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.
July 18, 2018 at 2:29 PM #10612Anh Tran
KeymasterHi Dan,
I'm not really clear about this issue. Can you explain what you're trying to do?
July 18, 2018 at 2:43 PM #10613Dan
ParticipantSure- 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!
July 18, 2018 at 5:01 PM #10616Anh Tran
KeymasterI 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.
July 18, 2018 at 5:19 PM #10618Dan
Participantyeah 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
-
AuthorPosts
- The topic ‘Form Hooks/Filters for multisite CPT conditional switching situation?’ is closed to new replies.