Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

hiphopinenglish on "Custom Taxonomy Meta Field for Bandcamp embed"

$
0
0

I've been using Custom Taxonomies for a while, so I'm quite familiar with them. However, on my latest project, I've found myself stumped by something. I'm creating Meta Fields for a Custom Taxonomy, and whilst they work great for links, and dates, and basic information like that, I'm having issues using them with embed codes from Bandcamp (And Soundcloud).

// Add Showcase Meta Field to custom taxonomy

// Add term page
function taxonomy_add_new_meta_field_showcase() {
	// this will add the custom meta field to the add new term page
?>
	<div class="form-field">
		<label for="term_meta[showcase_meta]"><?php _e( 'Paste PRODUCER Showcase here, or album Bandcamp/Soundcloud link.', 'producers' ); ?></label>
		<input type="text" name="term_meta[showcase_meta]" rows="4" cols="50" id="term_meta[showcase_meta]" value="">
		<p class="description"><?php _e( 'Paste PRODUCER Showcase here, or album Bandcamp/Soundcloud link.','producers' ); ?></p>
	</div>
<?php
}
add_action( 'hhie_producers_add_form_fields', 'taxonomy_add_new_meta_field_showcase', 10, 2 );
//Edit function for custom meta field

// Edit term page
function taxonomy_edit_meta_field_showcase($term) {

	// put the term ID into a variable
	$t_id = $term->term_id;

	// retrieve the existing value(s) for this meta field. This returns an array
	$term_meta = get_option( "taxonomy_$t_id" ); ?>
	<tr class="form-field">
	<th scope="row" valign="top"><label for="term_meta[showcase_meta]"><?php _e( 'Paste PRODUCER Showcase here, or album Bandcamp/Soundcloud link.', 'producers' ); ?></label></th>
		<td>
			<input type="text" name="term_meta[showcase_meta]" rows="4" cols="50" id="term_meta[showcase_meta]" value="<?php echo esc_attr( $term_meta['showcase_meta'] ) ? esc_attr( $term_meta['showcase_meta'] ) : ''; ?>">
			<p class="description"><?php _e( 'Paste PRODUCER Showcase here, or album Bandcamp/Soundcloud link.','producers' ); ?></p>
		</td>
	</tr>
<?php
}
add_action( 'hhie_producers_edit_form_fields', 'taxonomy_edit_meta_field_showcase', 10, 2 );

//Save function for custom meta field
// Save extra taxonomy fields callback function.
function save_taxonomy_custom_meta_showcase( $term_id ) {
	if ( isset( $_POST['term_meta'] ) ) {
		$t_id = $term_id;
		$term_meta = get_option( "taxonomy_$t_id" );
		$cat_keys = array_keys( $_POST['term_meta'] );
		foreach ( $cat_keys as $key ) {
			if ( isset ( $_POST['term_meta'][$key] ) ) {
				$term_meta[$key] = $_POST['term_meta'][$key];
			}
		}
		// Save the option array.
		update_option( "taxonomy_$t_id", $term_meta );
	}
}
add_action( 'edited_hhie_producers', 'save_taxonomy_custom_meta_showcase', 10, 2 );
add_action( 'create_hhie_producers', 'save_taxonomy_custom_meta_showcase', 10, 2 );

When calling this in my page template, I get the weirdest output when using <iframe>from Bandcamp. Here's the code that I've used on my page template:

<?php $array=get_option('taxonomy_' . $term->term_id); ?>
			<?php $showcase=$array['showcase_meta']; ?>
			<?php if ( !empty( $showcase) ) : ?>
			<div class="producershowcase">
			<?php echo wpautop( $showcase) ; ?>
			<?php endif; ?>
			</div>

I've also tried without wpautop but to no avail.

I've also tried using textarea rather than textas my input type, and that hasn't worked either.
Hopefully, someone can shed some light - I may well have neglected somethnig very obvious. Thanks.
(Current output can be seen here - notice the weird iframe of my site instead of the intended Bandcamp one)


Viewing all articles
Browse latest Browse all 8245

Trending Articles