• Hi,

    I really love this plugin, and I am really new to working with php.

    I was wondering if someone might be able to help me figure out how to assign a unique value to each custom field within a field-set.

    I can currently add multiple fields and display them from an array, however the fields don’t “group together” the way I want them to.

    For example, I have 2 custom fields into which I enter “venue” data and “event” data.

    There are multiple venues and events for each day of the week. When I display the values of each of the arrays, the venue and event data to line up the way I entered them.

    I believe I need to assign a unique ID to each “coupling”, but I am unclear on exactly how to do this.

    If anyone could point me in the direction of learning more, I would greatly appreciate it.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hey there,

    At the moment this is really buggy. I can only guess what your custom fields look like as you haven’t posted them up.

    Here is something I’ve worked on just recently.

    [accordion_fieldset]
    type = fieldset_open
    class=accordion
    multiple = true
    multipleButton = true
    
    [accordion_title]
    type = textfield
    label = Accodion Title
    class = text
    blank = true
    
    [accordion_introtext]
    type = textfield
    label = Teaser text for the Accordion
    class = text
    blank = true
    
    [accordion_content]
    type = textarea
    hideKey = true
    label = Content for the Accordion
    blank = true
    class = sharedescription
    
    [accordion_fieldset]
    type = fieldset_close

    Make sure blank is set to true on your fields. You want the to occupy space in the database so everything lines up. Also the naming convention is ‘accordion_’. This is important because you’ll be using this to to do a like search from the database.

    In your functions add this function I’ve written.

    /**
    * Constructs an ordered array from cf metadata
    *
    * @param string	$like_item set in the CFT plugin based on the repeating fieldset name e.g. "test" would use 'test_fieldset'.
    * Keep the meta_key unique.
    * @return array	associated array
    */
    function get_cft_repeating_data( $like_item ){
    	global $post, $wpdb;
    
    	$sql = "SELECT * FROM $wpdb->postmeta	WHERE post_id = $post->ID AND meta_key LIKE '%" . $like_item . "%' ORDER BY meta_id ASC";
    
    				$data_objects = $wpdb->get_results($sql);
    				$project = array();
    				$i = 0;
    				$fieldset = $like_item . '_fieldset';
    				foreach($data_objects as $data) {
    
    					// the name of the fieldset:
    
    					if ( $data->meta_key == $fieldset ) {
    							$limit = $data->meta_value;
    					}
    
    					$i = ( $i <= $limit ) ? $i : 1;
    
    					if( $data->meta_value != $limit && $data->meta_value !='' ) {
    						$project[$i]["$data->meta_key"] = $data->meta_value;
    					}
    					$i++;
    				}
    
    	if(!$limit && user_logged_in() )
    	  echo 'Could not establish Custom Field Limit. The $like_item set was ' .$like_item . '<br /> SQL query was ' . $sql;
    	else
    		return $project;
    }

    In your template you can call your function with

    $accordion_data = get_cft_repeating_data('accordion');
    print_r($accordion_data);

    And that should have your custom fields in order.

    When I mention this is buggy I mean that I found while entering data into the Custom Field Template sometimes you’d push update and randomily custom fields would be lost. Quite frustrating.

    The other thing is that I’ve experienced is that you can’t use TinyMCE on textareas. Although they show up, the ids are all the same when you duplicate them, so when editing the duplicated field only the first field would be affected.

    Long rambling post. I hope this helps.

    Thread Starter Michael

    (@mlove2k2)

    Hey proximity2008,

    Wow!

    Thank you so much for your help!

    I will try and implement this solution.

    I found another way around the issue, with some help, but I would like to try this approach out as well.

    I really appreciate you taking the time to help me!

    Thank you!

    Hey Michael,

    Please post back your findings with the alternate solution. Would be good to share and see if there is an easier way.

    Thanks.

    This is quite interesting, I stumbled into this very same problem this afternoon but ended up sidestepping it completely and scrapping the concept of trying to make multiple arrays sit nicely next to one another and instead used a single textarea.

    I think I’ll investigate this further and see what happens…

    My solution is the following code, where lista is replaced by the custom field id, and the unordered list, ul#duplist separates each group.

    <ul id="duplist">
    <li>
    <?php
    $lista = get_post_custom_values('lista', $post->ID);
    foreach ( $lista as $key => $value ) {
    echo $value . '</li><li>';
    }
    ?>
    </li>
    </ul>

    Is there a fix to the issue involving other custom fields randomly being wiped out when updating? I’m trying to create a form for a client and just like Proximty said at various times the content of all other custom fields are being erased. It’s so annoying that I’m thinking of scrapping the “add new multiple field” option and just creating physical fields, say 8 total fieldsets, and telling the client “you can put in a total of 8 content blocks and that’s it”.

    In theory the “multiple = TRUE” option sounds great but if it wipes out the data for other fields for no apparent reason I can’t release that to the client.

    Has anyone figured out a foolproof solution?

    Has anyone figured out the issue regarding data being wiped…or not being stored properly?

    I gave up on the “multiple field” option. I started developing something for a client (a page template that had a ton of data input fields, all feeding into a specific page template) and in testing ALL of the custom field data on the page was wiped out when I tried to add another data group. There is absolutely no way I could release something like that to a client.

    My solution wasn’t much of a solution… I created 4 groups of content in the custom field form and told the client “this template page will allow for up to 4 groups of data, if you find you need more I’ll add additional groups”. Obviously giving the client the ability to just click a button/link to add another group is ideal but if doing so wipes out any work they put into that page I’ll probably never get any more work from them again.

    I completely understand. I am working on a project for a client that requires the multi-fields and multi-fieldsets option to be enabled. The project progress has slowed down significantly (because of this plugin’s limitation) but I am breaking my balls to get this thing figured out.

    If you figure it out, please let me know. The plugin, minus the multi option, has been a huge help in my client projects. Other than the multi option, there is one other stupid thing that would be really helpful… the ability to add section breaks in the custom field forms where you could put some basic text (ie. headers, descriptions, instructions). If you’ve ever used the Gravity Forms plugin for front-end forms you can do this. It would be nice if you could do this with the custom field template plugin.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: Custom Field Template] Unique ID of Each Instance of a Multiple Field’ is closed to new replies.