Last active
August 28, 2017 11:34
-
-
Save svenl77/6492f14433eafd680f045f1269c0b50d to your computer and use it in GitHub Desktop.
Create WordPress Gallery from BuddyForms File Form Element to use in a ShortCode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Register the new Shortcode | |
add_shortcode( 'my_bf_gallery_shortcode' , 'my_custom_gallery_shortcode' ); | |
// ShortCode function: | |
function my_custom_gallery_shortcode($attr){ | |
global $post, $buddyforms; | |
extract(shortcode_atts(array( | |
'form_element_slug' => '', | |
), $attr)); | |
if(is_admin()) | |
return; | |
// get the form element (custom field) values | |
$gallery = get_post_meta($post->ID, $form_element_slug, true); | |
if(!$gallery) | |
return; | |
// Create a "," seperated string from the attachement ids | |
$gallery = implode(',', $gallery); | |
// create the WP Gallery Shortcode and return it | |
$gallery_shortcode = '[gallery ids="'. $gallery .'"]'; | |
return apply_filters( 'the_content', $gallery_shortcode ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment