Support

Account

Home Forums Add-ons Gallery Field How to extract the serialized array Reply To: How to extract the serialized array

  • Yes, Something like this

    
    //conection... bla bla bla or
    global $wpdb;
    
    $single ="SELECT DISTINCT
    ID AS id,
    post_title AS title,
    (SELECT meta_value FROM ".$wpdb->posts." WHERE post_id = ID AND meta_key = 'images') AS images
    FROM
    ".$wpdb->posts."
    WHERE
    post_status = 'publish' AND
    post_type = 'property'
    ";
    
    foreach($wpdb->get_results($single, OBJECT) as $rss) {
    
    $img = $rss->images;
    $gallery = unserialize( $img );
    $images = implode(", ", $galeria);
    $photos = "SELECT
    meta_value AS photos
    FROM
    ".$wpdb->postmeta."
    WHERE
    ".$wpdb->postmeta.".meta_key =  '_wp_attached_file' AND
    ".$wpdb->postmeta.".post_id IN($imagens)
    ";
    foreach($wpdb->get_results($photos, OBJECT) as $rss) {
     echo $rss->photos; // 2016/01/photo.jpg
    }
    }