Attach files

<?php

//Add this snippet to functions.php - the 'input_3' is the name of the file upload field in gravity forms, the category 11 is the category your form posts to
function add_mp3_customfield($post){
if(isset($_FILES['input_3']) && in_category(11,$post)){
add_post_meta($post,'interview_mp3',$_FILES['input_3']['name']);
}
}
add_action('publish_post','add_mp3_customfield');
//End snippet number 1

//This is an example loop, for your template file, the real version creates links to play the mp3's but this example just prints out the filepath. Replace the number 8 with the id of your particular gravity form.

if( have_posts() ) : while ( have_posts() ) : the_post();

$mp3_filename = get_post_meta($post->ID, 'interview_mp3', true);
$mp3_path = 'http://' . $_SERVER['SERVER_NAME'] . '/wp-content/uploads/gravity_forms/8/' . date('Y') . '/' . date('m') . '/' . $mp3_filename;

echo $mp3_path;
echo '<br>';

endwhile;
endif;

?>

0 Comments

You must be logged in to post a comment.