• Using this plugin, I’ve run into a small issue with it and the custom post types feature in 3.0. I have two custom post types created, and want to use the plugin to add a different set of custom fields to each of these post types.

    However, it seems as though the 2nd template I add, no matter what is in it, does not seem to work. The first template works with the first custom post type, but the second does not show any custom fields. I’ve tried switching the templates, and it does not matter which order I input them, only the first template works. I see the Custom Post Template header and the initialize/save buttons on the 2nd, but no fields.

    Ideas? Is this a bug or am I simply doing something wrong?

Viewing 16 replies (of 16 total)
  • As an update to Rhand’s mention, I’ve updated that post to include a much better function for handling custom field data:

    For functions.php:

    // Get all custom fields attached to a page
    if( !function_exists('base_get_all_custom_fields') ) {
    	function base_get_all_custom_fields(){
    		global $post;
    		global $wpdb;
    		$sql = "SELECT * FROM $wpdb->postmeta	WHERE post_id = $post->ID ORDER BY meta_id ASC";
    		$custom_fields = $wpdb->get_results($sql);
    		$custom_field_array = array();
    		foreach($custom_fields as $field) {
    			$custom_field_array["$field->meta_key"] = $field->meta_value;
    		}
    		return $custom_field_array;
    	}
    }

    In your template:

    <?php
    // Get all custom fields attached to this post and store them in an array
    $custom_fields = base_get_all_custom_fields();
    ?>
    
    <?php if( !empty($custom_fields['cft_tinymce_1']) ) { ?>
    <div id="block-1" class="content-box">
    	<h2>Block #1</h2>
    	<div class="entry">
    		<?php echo $custom_fields['cft_tinymce_1']; ?>
    	</div>
    </div>
    <?php } ?>
    
    <?php if( !empty($custom_fields['cft_tinymce_2']) ) { ?>
    <div id="block-2" class="content-box">
    	<h2>Block #2</h2>
    	<div class="entry">
    		<?php echo $custom_fields['cft_tinymce_2']; ?>
    	</div>
    </div>
    <?php } ?>
Viewing 16 replies (of 16 total)
  • The topic ‘[Plugin: Custom Field Template] Multiple templates/custom post types’ is closed to new replies.