[Plugin: Custom Field Template] Multiple templates/custom post types
-
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?
-
how did you create the custom post types?
i have used the ‘custom post types’ plugin, then i specified which custom post names i wanted to add the fields to in the custom fields plugin. the list of the custom post types is a comma-delimited field under template
the interesting thing is that it doesn’t matter in which template you enter the name of the custom post type: the list of templates will become available in your custom posts types.
i’m guessing that this is a small bug, but at least it should show the custom fields… i’m still trying to figure out exactly how this things work. hope this helps
Created custom post types through the functions.php file rather than a plugin.
I have two different post types – events and recipes. I’d like a different set of custom fields to show up for each. I have two templates created, one set to show on the recipes post type, the other set to show on the events post type. The second template doesn’t seem to work no matter what I do; I can get the first to show up on one or both of the post types. If I swap the order of the templates, the first one works regardless.
In order to create custom post types, please use some plugins like Custom Post Type UI. When you set the custom post type in the custom field template options, you may have a space between each type.
This does not work correctly.
events, recipes
This works.
events,recipes
I will fix this in the future release. Thanks.
Just transitioned by custom post types from the functions file to the plugin. CFT still doesn’t work on the 2nd custom template. I do not have spaces, rather, one cft is for ‘recipes’ (the first – this one works) and the second cft is for ‘events’ (this one does not work). All I see on the events post edit page is the Custom Field Template header (not even my custom box header) followed by the initialize/save buttons. But no fields.
If I switch the two fields, putting the events in the template #0 spot, it works, while the recipes template in the template #1 spot does not.
I am having this same problem, actually–or perhaps it’s only similar. I created my custom post types using functions.php, because I wanted greater control than plugins are currently offering. (I also don’t want to have to deal with yet another plugin not being updated.)
In my case, I have four custom post types:
portfolio-artwork
portfolio-photography
portfolio-webdesign
portfolio-writingAll of these work on the backend perfectly with their taxonomies, so I don’t think there’s an issue with the post types. Unfortunately, I cannot seem to assign custom field templates to multiple custom post types (no, I was not using a space after the comma), nor can I just duplicate the template and assign it to another post type.
I had a play around, and I discovered something strange. In functions.php, I’ve got my portfolio-artwork custom post type created first, followed by portfolio-photography. Now, if I make a custom field template for portfolio-artwork, it works, but I can never get one to work for any of the other post types that are created after it in functions.php.
However, if I switch one of the other post types to the top of functions.php, custom field template then works with it, but not the others. In other words, it’s only recognizing the first created custom post type. It seems like there may be some issue with register_post_type being used more than once for custom field templates? I’m not sure. I don’t see how using a plugin to create the post types would change this sort of issue, and I’d really rather not venture down that road.
Great plugin, but seriously hoping I can get this to work!
Cheers,
LeliaHi guys,
I tried fixing the template loading. Please upgrade to 1.6.9. Thanks.Thanks Hiroaki! It does appear to be working now for multiple templates, everything except the custom box title (always shows the Template #0 title, even for template #1 fields). Not nearly as big of a deal, at least the fields are showing up now. ??
Thanks!
Hi, I’m still having a problem to make Custom Field Template to appear in custom post types.
I have created the custom post types through function.php and list them in the “Custom Post Type (comma-deliminated):”field without space but comma. Custom Field Template appears in the default post (I have specified in Post type: section) but it doesn’t appear in the custom post types I have created. The panel is there but none of the fields show up.
What am I missing? Please let me know.
Thanks!
P.S. I’m testing this using Twentyten theme and no other plugin activated. The plugin version is Version 1.7.1
Update!!
If I specified “Both” in “Post Type:” section rather than just “Post”, fields start appear!!Had the same problem, iamtakashi. Strange thing is, everything worked fine for a while. When I changed to “Both” instead of just “Posts”, the template started working again as well.
hi, nice plugin
but same problem too, i test with WP Post Type UI, Custom Post Type UI, CMS Press plugin and it work for a while. but after i rename one custom post type i cannot get CFT appeare anymore in any custom post type…..
usin wp3.0.1 and cft 1.7.5
Hi Hiroaki
i confirm the problem, i use cft with wp-post-type-ui plugin, i have 2 templates, only the first work well only when no template is disabled (perhaps this is the key), if i disabled the 2nd template then the first template come empty (it only appear the title of cft box panel)
best regard,
pescaditoand if use the second template it doesn’t work too
Same issue here. Would love to see the code for your custom post types. Here is mine I use in functions.php for one custom post type:
// add custom port type and custom taxonomy add_action('init', 'destinations_register'); function destinations_register() { $labels = array( 'name' => _x('Destinations', 'post type general name'), 'singular_name' => _x('Individual Destination', 'post type singular name'), 'add_new' => _x('Add New', 'individual destination'), 'add_new_item' => __('Add New Destination'), 'edit_item' => __('Edit Individual Destination'), 'new_item' => __('New Destination'), 'view_item' => __('View Portfolio Item'), 'search_items' => __('Search Destinations'), 'not_found' => __('Nothing found'), 'not_found_in_trash' => __('Nothing found in Trash'), 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'menu_icon' => get_stylesheet_directory_uri() . '/article16.png', 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title','editor','thumbnail') ); register_post_type( 'destinations' , $args ); } register_taxonomy("Resorts", array("destinations"), array("hierarchical" => true, "label" => "Resorts", "singular_label" => "Skill", "rewrite" => true));
It works in the backend and I added dummy text to three custom fields I made using Custom Fields Template. They do not show up in the custom post type in the frontend. I do see
<dl class="ctf ctf 0"></dl>
in the source codeWell, I managed to do it with an addition to my functions.php following https://www.kevinleary.net/advanced-content-management-wordpress-custom-field-templates/ :
// Get Custom Field Template Values function getCustomField($theField) { global $post; $block = get_post_meta($post->ID, $theField); if($block){ foreach(($block) as $blocks) { echo $blocks; } } }
This does load the fields well with additional code in my singel-x.php :
<div id="block-1" class="content-box"> <h2>Block #1</h2> <div class="entry"> <?php getCustomField('Overview'); ?> </div> </div> <div id="block-2" class="content-box"> <h2>Block #2</h2> <div class="entry"> <?php getCustomField('Room Features'); ?> </div> </div>
This code is still rough and needs to be redone, but all works well.
I prefer to use shortcode rather than the ‘getCustomField’ function :
<?php echo do_shortcode('[cft key=Description]') ; ?>
But it’s really just a matter of choice.
It suit better my needs to get the value and be able to work on it rather than echo-ing it out of the box.For example, VCarrousel can be an image or a flash file.
<?php //on récupère l'id de l'objet attaché $idvc = do_shortcode('[cft key=VCarrousel]'); //si c'est une image, on l'affiche au format 160x160 pixels if (wp_attachment_is_image($idvc)) { echo wp_get_attachment_image($idvc , 'attachment-160x160' ) ; } //si c'est pas une image else { //on vérifie si c'est du flash if (preg_match('@(shockwave|flash)@i',get_post_mime_type($idvc))) { echo do_shortcode('[swfobj src="'. wp_get_attachment_url($idvc) . '" dynamic_embed="true" play="false"]'); } } ?>
which you could not do with the simple getCustomField function.
- The topic ‘[Plugin: Custom Field Template] Multiple templates/custom post types’ is closed to new replies.