반응형
JSON API Wordpress가 App을 통해 업로드 시 피처링 이미지를 표시하지 않음
워드프레스 피처 이미지에 대해 알 수 없는 문제가 발생했습니다.웹사이트에서 피처링 이미지를 업데이트하면 json을 통해 앱에 표시됩니다.
그러나 json을 통해 wordpress db에 이미지를 업로드하면 출력은 image 필드에 NULL이 됩니다.
db를 보면 이미지 경로가 있고 경로가 404로 연결되지 않습니다.
이미지 경로: http://www.indiafastener.com/webservices/listing/uploads/2017-04-01_12-01-40IMG-20150715-WA0004.jpg
이미지가 없는 것이 원인일 수도 있습니다.wp-content/uploads/2016/02/
폴더?
이미지 업로드 코드
require_once('../../wp-config.php');
require_once('../../wp-admin/includes/image.php');
$dirname = "../../wp-content/uploads/2017/01/";
$filename = $_FILES["file"]["name"];
$attachment = array(
'post_mime_type' => 'image/jpeg',
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => '',
'post_status' => 'inherit',
'guid' => $dirname.basename($filename)
//'wp-content/uploads/2017/01/' . basename($filename)
);
$your_post_id = 1392;
$attach_id = wp_insert_attachment( $attachment, $filename,'$your_post_id' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
//$id=1385;
update_post_meta($id, '_thumbnail_id', $attach_id);
echo "success";
이에 대한 어떠한 도움도 매우 감사할 것입니다.
스크린샷
DB post_type 첨부파일을 앱을 통해 업로드
이미지 ID에 링크된 DB Post
이미지 미리보기 누락:
당신의 코드는 확실치 않지만, 아래의 코드 조각은 이미지를 게시용 피쳐 이미지로 할당하기 위해 완벽하게 작동하고 있습니다.확인 부탁드립니다.첨부 ID는 미립자 포스트에 할당되어야 합니다.게시 메타 '_meta_id'도 확인하세요.
require_once(ABSPATH . 'wp-admin/includes/image.php');
$filename = 'your file name';
$attachment = array(
'post_mime_type' => 'your mime type',
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => '',
'post_status' => 'inherit',
'guid' => $wp_upload_dir['url'] . '/' . basename($filename)
);
$attach_id = wp_insert_attachment( $attachment, $filename,'your_post_id' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
update_post_meta($id, '_thumbnail_id', $attach_id);
언급URL : https://stackoverflow.com/questions/41501230/json-api-wordpress-not-showing-featured-image-when-uploaded-via-app
반응형
'prosource' 카테고리의 다른 글
Redux 연결 컴포넌트는 재렌더 타이밍을 어떻게 알 수 있습니까? (0) | 2023.03.09 |
---|---|
Material-UI에서 TextField의 밑줄을 삭제하려면 어떻게 해야 합니까? (0) | 2023.03.09 |
Angular에서 체크박스를 클릭했을 때 응답하는 방법JS 디렉티브? (0) | 2023.03.09 |
여러 테이블에서 카운트(*)를 선택합니다. (0) | 2023.03.04 |
styled-components - html 또는 본문 태그에 스타일을 설정하는 방법 (0) | 2023.03.04 |