Skip to content

Instantly share code, notes, and snippets.

@tareq1988
Created March 21, 2013 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tareq1988/5213621 to your computer and use it in GitHub Desktop.
Save tareq1988/5213621 to your computer and use it in GitHub Desktop.
<?php
function wpuf_show_custom_fields( $content ) {
global $post;
$form_id = get_post_meta( $post->ID, '_wpuf_form_id', true );
if ( !$form_id ) {
return $content;
}
$html = '<ul class="wpuf_customs">';
$form_vars = get_post_meta( $form_id, 'wpuf_form', true );
$meta = array();
if ( $form_vars ) {
foreach ($form_vars as $attr) {
if ( isset( $attr['is_meta'] ) && $attr['is_meta'] == 'yes' ) {
$meta[] = $attr;
}
}
if ( !$meta ) {
return $content;
}
foreach ($meta as $attr) {
if ( $attr['input_type'] == 'image_upload' ) {
$images = get_post_meta( $post->ID, $attr['name'] );
$image_html = '<li><label>' . $attr['label'] . ':</lable> ';
if ( $images ) {
foreach ($images as $attachment_id) {
$thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
$full_size = wp_get_attachment_url( $attachment_id );
$image_html .= sprintf( '<a href="%s">%s</a> ', $full_size, $thumb );
}
}
$html .= $image_html . '</li>';
} else if ( $attr['input_type'] == 'file_upload' ) {
$images = get_post_meta( $post->ID, $attr['name'] );
$image_html = '<li><label>' . $attr['label'] . ':</lable> ';
if ( $images ) {
foreach ($images as $attachment_id) {
$full_size = wp_get_attachment_url( $attachment_id );
$image_html .= sprintf( '<a href="%s">%s</a> ', $full_size, get_post_field( 'post_title', $attachment_id ) );
}
}
$html .= $image_html . '</li>';
} else {
$value = get_post_meta( $post->ID, $attr['name'] );
$html .= sprintf( '<li><label>%s</label>: %s</li>', $attr['label'], implode( ', ', $value ) );
}
}
}
$html .= '</ul>';
return $content . $html;
}
add_filter( 'the_content' , 'wpuf_show_custom_fields' );
@birdbrainsolutions
Copy link

"Site is experiencing technical difficulties" after adding this to functions.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment