본문 바로가기

프로그램 경험/PHP

[WordPress] 워드프레스 멀티 사이트일때 포스트 저장

멀티 사이트일 경우에 각 사이트를 선택해서 저장해야 한다.

아래와 같이 해당 블로그 사이트를 선택해서 하면 된다.


$title = $_POST['title'];
$author_id = $_POST['author_id'];
$reference = $_POST['reference'];
$blog_id = $_POST['blog_id'];

$my_post = array(
 'post_title' => $title,
 'post_status' => 'pending',
 'post_author' => $author_id,
 'post_type' => 'order'
);

switch_to_blog($blog_id);
$new_id = wp_insert_post( $my_post );
update_post_meta($new_id, "reference", $reference);
restore_current_blog();

출처 : http://wordpress.org/support/topic/wp_insert_post-in-current-blog