내 미디어 파일 이미지의 이름은 'icon_0001', 'icon_0002', 'icon_0003', 'illustration_0001', 'illustration_0002', 'illustration_0003'등이며 다른 이미지 파일과 마찬가지로 'SummonClear', 'StunPowder'등. 나는 이것을 wordpress admin ui와 함께 확인했고, 또한 첨부 파일을 var_dumping하여 확인했다.post_title로 미디어 이미지 파일 받기
그리고 지금은 다음 코드로 미디어 파일 ID를 검색하려고 :
$post_name = 'illustration_30004';
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_title' => trim($post_name),
'post_mime_type' => 'image/png',
'posts_per_page' => -1
);
$wp_query = new WP_Query($args);
foreach($wp_query->posts as $image) {
var_dump($image);
echo '<hr/>';
}
예,이 post_type = attachment
를 사용하여 단순한 쿼리 코드입니다. 그러나, 나는 $post_name
에게주는 어떤 이름, 쿼리, 미디어 라이브러리에있는 모든 이미지 파일을 표시 다음과 같은 :
object(WP_Post)#1386 (24) { ["ID"]=> int(40735) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2014-10-08 10:22:04" ["post_date_gmt"]=> string(19) "2014-10-08 10:22:04" ["post_content"]=> string(0) "" ["post_title"]=> string(11) "SummonClear" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "inherit" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(13) "summonclear-3" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2014-10-08 10:22:04" ["post_modified_gmt"]=> string(19) "2014-10-08 10:22:04" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(104) "http://101.251.201.22/digital-opal-mu/elin-expedition/wp-content/uploads/sites/2/assets/SummonClear2.png" ["menu_order"]=> int(0) ["post_type"]=> string(10) "attachment" ["post_mime_type"]=> string(9) "image/png" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }
object(WP_Post)#1387 (24) { ["ID"]=> int(40734) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2014-10-08 10:22:04" ["post_date_gmt"]=> string(19) "2014-10-08 10:22:04" ["post_content"]=> string(0) "" ["post_title"]=> string(11) "SummonChick" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "inherit" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(13) "summonchick-3" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2014-10-08 10:22:04" ["post_modified_gmt"]=> string(19) "2014-10-08 10:22:04" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(104) "http://101.251.201.22/digital-opal-mu/elin-expedition/wp-content/uploads/sites/2/assets/SummonChick2.png" ["menu_order"]=> int(0) ["post_type"]=> string(10) "attachment" ["post_mime_type"]=> string(9) "image/png" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }
object(WP_Post)#1388 (24) { ["ID"]=> int(40733) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2014-10-08 10:22:04" ["post_date_gmt"]=> string(19) "2014-10-08 10:22:04" ["post_content"]=> string(0) "" ["post_title"]=> string(10) "StunPowder" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "inherit" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(12) "stunpowder-3" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2014-10-08 10:22:04" ["post_modified_gmt"]=> string(19) "2014-10-08 10:22:04" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(103) "http://101.251.201.22/digital-opal-mu/elin-expedition/wp-content/uploads/sites/2/assets/StunPowder2.png" ["menu_order"]=> int(0) ["post_type"]=> string(10) "attachment" ["post_mime_type"]=> string(9) "image/png" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }
object(WP_Post)#1389 (24) { ["ID"]=> int(40732) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2014-10-08 10:22:04" ["post_date_gmt"]=> string(19) "2014-10-08 10:22:04" ["post_content"]=> string(0) "" ["post_title"]=> string(5) "Stomp" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "inherit" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(7) "stomp-3" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2014-10-08 10:22:04" ["post_modified_gmt"]=> string(19) "2014-10-08 10:22:04" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(98) "http://101.251.201.22/digital-opal-mu/elin-expedition/wp-content/uploads/sites/2/assets/Stomp2.png" ["menu_order"]=> int(0) ["post_type"]=> string(10) "attachment" ["post_mime_type"]=> string(9) "image/png" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }
...and 900+ more of these.
나는 결과에 포함되어 있기 때문에 아래의 이름 'illustration_30004'와 미디어 파일을 알고 900 개 이상의 결과.
object(WP_Post)#1871 (24) { ["ID"]=> int(40973) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2014-10-07 03:38:14" ["post_date_gmt"]=> string(19) "2014-10-07 03:38:14" ["post_content"]=> string(0) "" ["post_title"]=> string(18) "illustration_30004" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "inherit" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(18) "illustration_30004" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2014-10-07 03:38:14" ["post_modified_gmt"]=> string(19) "2014-10-07 03:38:14" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(110) "http://101.251.201.22/digital-opal-mu/elin-expedition/wp-content/uploads/sites/2/assets/illustration_30004.png" ["menu_order"]=> int(0) ["post_type"]=> string(10) "attachment" ["post_mime_type"]=> string(9) "image/png" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }
그래서 질문은 ... 내 쿼리 잘못 무엇이며 왜 내가 대신 내가 원하는 post_title
의 모든 미디어 파일을 무엇입니까?
추가 : 한 가지 더 -이 미디어 파일은 워드 프레스에 업로드되었지만 아직 어떤 포스트에도 첨부되지 않았습니다.
Bizzkit가/제안 주셔서 감사합니다,하지만이 미디어 파일 내가 미디어 파일 '슬러그'를 생각하지? – Dongsan
라이브러리에 가서 첨부 파일을 클릭 한 다음 "첨부 파일 페이지보기"또는 "자세한 내용 편집"을 선택하여 볼 수 있습니다. 첨부 파일 페이지의 URL이나 첨부 파일 편집기 페이지의 슬러그 편집 슬롯 (포스트 편집 페이지와 동일)에서 슬러그를 볼 수 있습니다. 이게 도움이되는지 알려주세요! – Yavor