Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Returns an array of image IDs stored in gllery meta field
- *
- * @param string $field_key Gallery field meta key
- * @param int $post_id Post ID to get field from. If not set - will try to use current post.
- * @return array
- */
- function my_get_jet_engine_gallery( $field_key = '', $post_id = null ) {
- $gallery = array();
- if ( ! $post_id ) {
- $post_id = get_the_ID();
- }
- if ( ! $post_id || ! $field_key ) {
- return $gallery;
- }
- $meta = get_post_meta( $post_id, $field_key, true );
- if ( ! $meta ) {
- return $gallery;
- }
- $gallery = explode( ',', $meta );
- return $gallery;
- }
- /**
- * Usage example for field with name '_gallery' and some specific post
- */
- $gallery = my_get_jet_engine_gallery( '_gallery', 156 );
- foreach ( $gallery as $img_id ) {
- echo wp_get_attachment_image( $img_id );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement