2014-02-13 2 views
0

WordPress 용 사용자 정의 게시물 제출 양식을 작성 중입니다. 게시물을 작성하고 이미지를 업로드하여 게시물에 첨부 할 수 있지만 다음 단계는 어려움을 겪고 있습니다. - 내가 자동으로 게시물에 표시되는 업로드 된 이미지를 찾고 있어요, 필자는 기능을 갖춘 이미지 옵션으로보고 있지만, 그냥 어떤 도움이Wordpress wp-insert-post 콘텐츠 내에서 이미지 첨부 첨부

+0

는 wp_insert_post 섹션에게 답장을 보내 – user3306104

답변

0

사용 set_post_thumbnail을 감사

$my_post = array(); 
$my_post['post_title'] = $newid; 
$my_post['post_content'] = $imageurl1.$imageurl.$config_basedir.$uploaddir.$id . ".gif". $imageurl2; 
$my_post['post_author'] = 1; 
$my_post['post_status'] = draft; 
$my_post['post_category'] = array($a); 
// Insert the post into the database 
$post_id = wp_insert_post($my_post); 
// 
$wp_filetype = wp_check_filetype(basename($id . ".gif"), null); 
$attachment = array(); 
$attachment['post_mime_type'] = $wp_filetype['type']; 
$attachment['post_title'] = $newid; 
$attachment['post_content'] = ''; 
$attachment['post_status'] = 'inherit'; 
$attach_id = wp_insert_attachment($attachment, $id . ".gif", $post_id) 
require_once(ABSPATH . "wp-admin" . '/includes/image.php'); 
$attach_data = wp_generate_attachment_metadata($attach_id, $filename); 
wp_update_attachment_metadata($attach_id, $attach_data); 
set_post_thumbnail($post_id, $attach_id); 
// 
wp_redirect(site_url()."?p=$post_id"); exit(); 

동작하지 않습니다. 게시물 개체 또는 ID를 전달할 수 있습니다. 썸네일 ID는 미디어 첨부 ID입니다. ; 필자 ($ post_id를, $ attach_id)로 set_post_thumbnail 전에이 추가 -

set_post_thumbnail($post, $thumbnail_id); 
+0

감사를 포함하는 코드를 업데이트 하지만 그건 바보 같은 짓을 할 수도 있습니다. – user3306104

+0

그럴 때 $ attach_id와 $ post_id가 설정 되었습니까? –

+0

wp_insert_post 훅에있는 코드를 포함 시키십시오. 올바른 방향으로 알려 드리겠습니다. –