Jimi Wikman
Member
Posted 3 years ago #
I am building up a portfolio using wordpress and I would like to add screenshots using the gallery, but in a way so I can hardcode it into the post template rather than adding a gallery tag in the post itself. I would like to use custom fields to add a gallery id so that I can set the correct gallery for each post/projekt.
Any pointers as to how to make this?
Jimi Wikman
Member
Posted 3 years ago #
Found the solution :)
<?php
$meta_id = $wp_query->post->ID; /* stores your post id in a variable */
/* This stores the defined gallery ID into a variable. Setting this to true makes sure it returns a string instead of an array */
$meta_gallery_id = get_post_meta( $meta_id, 'meta_gallery_id', true );
if( $meta_gallery_id != '' ) {
$meta_gallery = '[gallery=' . $meta_gallery_id . ']';
$meta_gallery= apply_filters( 'the_content', $meta_gallery );
echo $meta_gallery;
}
?>