In order to save all values in the right fields, you need to add blank = true
attribute. Even if you make the field blank, the blank value will be created. BTW, I tried your code, and I noticed it seemed that multiple tinyMCE textareas are not working properly. You had better use the normal textarea….
does the blank = true have to be in teh fieldset or the actual field. Also how do we control the ordering of items ..
Hi Inforcality,
At the moment I am doing something incredibly similar 😉
Here is what I came up with:
MY CFT CODE:
[project]
type = fieldset_open
multiple = true
multipleButton = true
[project_name]
type = textfield
size = 35
label = Project Name
class = project_name
blank = true
[project_image]
type=file
relation=true
label = upload image
class = project_image
blank = true
[project_type]
type=select
value = WordPress # Joomla! # Static
class = project_type
blank = true
[project_description]
type=textarea
rows=10
cols = 30
label = Description of Project
class = project_description
blank = true
[project_link]
label = Link to project
type = text
size = 35
class = project_link
blank = true
[project]
type = fieldset_close
So that will give you a rather jumbled data in the database.
The trick is the naming of the fields (you’ve got that sorted I see), I’ve used “project”. That will make it easier to retrieve and sort the data.
In your template:
// retrieve entries with project prefix
$sql = " SELECT * FROM $wpdb->postmeta WHERE post_id = $post->ID AND meta_key LIKE '%project%' ORDER BY <code>meta_id</code> ASC";
$data_objects = $wpdb->get_results($sql);
$project = array();
$i = 0;
foreach($data_objects as $data) {
// the name of the fieldset:
if($data->meta_key == 'project') {
$limit = $data->meta_value;
}
$i = ( $i <= $limit ) ? $i : 1;
if( $data->meta_value != $limit ) {
$project[$i]["$data->meta_key"] = $data->meta_value;
}
$i++;
}
//check data
//print_r($project);
foreach( $project as $key){
// you will need to check if the value is blank but you get the idea.
echo 'Project Name: ' . $key['project_name'] .'<br />';
echo 'Project Image: ' . $key['project_image'] .'<br />';
echo 'Project Type: '. $key['project_description'] .'<br />';
// etc....
}
I’m not the greatest programmer in the world but that should do it. It is untested at the moment and there are no data checks. But you get the idea.
Thank you for that piece of code- it was very helpful.
I still have a feeling, that it could be less complex- any idea of other workaround?
There also should be change from
$limit = $data->meta_value;
to
$limit = $data->meta_value+1;
– otherwise you miss last row.
There is one more major caveat to this repeating technique. You can’t use tinymce or html textarea content types.
When you push the “Add New” on the fieldset all the code is duplicated. You do get a new field but TinyMCE and the HTML editor are still tied to the original content area.
So when you use any javascript, it will affect the original textarea not the newly created one.
I’d love a fix for this.
Great fix!
But if I’m editing post and before I’ve added minimum 2 records, I see only delete button (no “Add new” button!?)
If I wan to add I’ve to delete all and then add all one more time.
My code:
[founder]
type = fieldset_open
multiple = true
multipleButton = true
[founder_txt]
hideKey = true
type = text
size = 50
label = Founder – Enter name and title
class founder_txt
blank = true
[founder_img]
hideKey = true
type = file
label = Founder – Upload photo
class = founder_img
blank = true
[class]
type = fieldset_close
Screenshot: http://imageshack.us/m/716/7684/cftvl.jpg
Hi cugok. You are opening and closing a fieldset with different names. That might be the problem.
Try changing the name of the opening or closing tag to match the other one. It might be a good idea to name them founder_fieldset.
Hey Ignacio! Thanks for fix! It works fine now 😉