/** * Get the contents of an ACF field. * * @param string $name The field name * @return mixed The field's data */ public function field($name) { foreach ($this->data as $post) { $fieldType = get_field_object($name, $post->ID)['type']; if (in_array($fieldType, ['text'])) { $post->{$name} = get_field($name, $post->ID); } elseif (in_array($fieldType, ['image'])) { $post->{$name} = Data::arrayToObject(get_field($name, $post->ID)); } } return $this->data; }
/** * Create an object casted array of the featured image in all sizes. * * @param integer $id The post objects ID * @return object|boolean The object casted array or false */ public static function images($id) { $sizes = self::imageSizes(); $urls = []; if (has_post_thumbnail($id)) { $image = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'full'); $image = pathinfo($image[0]); $extension = $image['extension']; $image = $image['dirname'] . '/' . $image['filename']; $urls['full'] = $image . '.' . $extension; foreach ($sizes as $size) { $urls[Data::spaceToCamelCase($size->name, '-')] = $image . '-' . $size->width . 'x' . $size->height . '.' . $extension; } return (object) $urls; } else { return false; } }