Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

php - Send ACF Frontend form Title through using publish_post in a multisite

I'm trying to accomplish something that shouldn't be too difficult. However, I cannot get it right. The situation is as followed: I have a multisite with 2 subsites. All the 3 sites have their own custom post types.

I am trying to achieve the following: when a custom post type post is create on site ID = 3 using an ACF Frontend Form, this automatically creates another custom post type post on site with ID = 2.

Using the code below I am able to cross-post the posts from site A to site B. However now I only need to send the title through the Front-end form. The updated code can be found below:

add_action('publish_holiday', 'add_surf_holiday', 10, 2);
function add_surf_holiday($post) {

    switch_to_blog(2);
 
/* the rest of the function code */
  $labels = array(
      'post_title'            => $_POST['acf']['name_surf_accommodation'],
      'post_status'           => 'publish',
      'post_type'             => 'surf-holidays'
  );

wp_insert_post( $labels );

restore_current_blog();

}

Does any of you have an idea how to solve this issue?

If anything is unclear, please let me know.

Hope to hear from you soon!

Cheers,

Hans

question from:https://stackoverflow.com/questions/65922067/send-acf-frontend-form-title-through-using-publish-post-in-a-multisite

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The issue maybe with where you have this code, and I'm making the assumption that you have placed it in functions.php and if so then you should remove it from there and then create a plugin with your code and Network Activate it. Have you tried this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...