Last active
August 28, 2017 11:24
-
-
Save svenl77/77bfdd04858a585bf482 to your computer and use it in GitHub Desktop.
Create WordPress Gallery from BuddyForms File Form Element and add the Gallery under the Content
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 | |
//Add a content filter to attache your Gallery. | |
add_filter('the_content', 'my_custom_gallery', 10, 1); | |
function my_custom_gallery($content){ | |
global $post, $buddyforms; | |
if(is_admin()) | |
return $content; | |
if(!isset($buddyforms['buddyforms'])) | |
return $content; | |
// check if the post is attached to a BuddyFormsm Form | |
$form_slug = get_post_meta($post->ID, '_bf_form_slug', true); | |
if(!$form_slug) | |
return $content; | |
if(!isset($buddyforms['buddyforms'][$form_slug])) | |
return $content; | |
// get the form element (custom field) values | |
$gallery = get_post_meta($post->ID,'FORMELEMENTSLUG', true); | |
if(!$gallery) | |
return $content; | |
// create the WP Gallery ShortCode and return it | |
return '[gallery ids="'. $gallery .'"]'. $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment