2016-10-26 2 views
0

내 자신의 방식으로 wp_attachment_metadata를 가져오고 싶습니다. 나는 파일 이름을 얻고 싶다 :wp_attachment_metadata에서 메타 값을 얻는 방법

a:5:{s:5:"width";i:500;s:6:"height";i:500;s:4:"file";s:25:"2016/08/sprite_1500ml.jpg";s:5:"sizes";a:5:{s:9:"thumbnail";a:4:{s:4:"file";s:25:"sprite_1500ml-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:25:"sprite_1500ml-300x300.jpg";s:5:"width";i:300;s:6:"height";i:300;s:9:"mime-type";s:10:"image/jpeg";}s:14:"shop_thumbnail";a:4:{s:4:"file";s:25:"sprite_1500ml-180x180.jpg";s:5:"width";i:180;s:6:"height";i:180;s:9:"mime-type";s:10:"image/jpeg";}s:12:"shop_catalog";a:4:{s:4:"file";s:25:"sprite_1500ml-300x300.jpg";s:5:"width";i:300;s:6:"height";i:300;s:9:"mime-type";s:10:"image/jpeg";}s:11:"shop_single";a:4:{s:4:"file";s:25:"sprite_1500ml-400x400.jpg";s:5:"width";i:400;s:6:"height";i:400;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}} 

글쎄, 나는 붙어있다. 해당 배열을 분리하는 방법을 모르겠습니다. 누구든지 파일 이름 (URL 파일)을 얻을 수 있도록 배열을 분리하는 방법을 알고 있습니다. 지금

내 코드 :

$command = $_GET['command']; 
switch ($command) { 
    case 'list_product': 

     $loop = new WP_Query( 
       array(
         'post_type' => 'product' 
        ) 
       ); 
     if($loop->have_posts()) : 

      $data = array("api_status" => 1, "api_message" => "success"); 
      $meta = array(); 
      while ($loop->have_posts()) : $loop->the_post(); 
        $meta[] = array(
         "id"   => get_the_ID(), 
         "post_name"  => get_the_title(), 
         "stock_status" => get_post_meta(get_the_ID(), '_stock_status', true), 
         "price"   => get_post_meta(get_the_ID(), '_price', true), 
         "reguler_price" => get_post_meta(get_the_ID(), '_regular_price', true), 
               "image"   => get_post_meta(get_the__ID(), '_wp_attachment_metadata', true), 
        ); 
      endwhile; 
     endif; 
     echo json_encode($meta); 
     break; 

내가 사용할 때 내 말 :

"image"   => get_post_meta(get_the__ID(), '_wp_attachment_metadata', true), 

내 결과가 무엇이든에게

을 보여 나던 내 코드에서 무엇을 개선 그래서 그 캔 작업 내가 원하는 걸 좋아해?

+0

어쩌면 [이 게시물] (http://wordpress.stackexchange.com/questions/18463/how-to-extract-data-from-a-post-meta-serialized-array) 도움이됩니다. –

+0

iam 미안 해요, 처음에''image "=> get_post_meta (get_the__ID(), '_wp_attachment_metadata', true)를 사용하면'doest는 데이터를 보여 줍니 다. –

답변

0

이미지 URL을 원하면 다른 방법을 보여줍니다. 나는 네가 spicific 한 게시물의 미리보기 이미지를 원한다고 생각한다.

// First we get the image id 
$post_thumbnail_id = get_post_thumbnail_id(get_the_ID()); 

// Then we get the image data, we will get an array with some informations 
$image = wp_get_attachment_image_src($post_thumbnail_id, 'large'); 

// the image url is the first index of this array 
$image_url = $image[0]; 

이 예에서는 large 버전의 이미지 URL을 제공합니다. 철저한 크기를 원한다면 예를 들어로 변경하십시오. meidum 또는 full. 자세한 내용은 documentation of wp_get_attachment_image_src()을 읽어보십시오.

이 코드는 루프 안에 있어야합니다. get_the_ID()이 현재 POST ID을 반환하는지 확인하십시오. POST 의 게시물 미리보기 이미지가인지 확인하십시오.

기본적으로 첨부 ID (이미지)의 ID가 있으면 이미지 URL을 얻을 수 있습니다.

+0

응답이 null 인 경우, 내 코드에이 코드를 입력해야하는 위치를 알려주십시오. 나는 내가이 코드를 넣어 어디에 잘못 생각합니다 –

+0

나는 내 대답을 업데이 트했습니다. –

관련 문제