Support

Account

Home Forums Add-ons Repeater Field Date appears wrong on repeater field and data transfer

Solved

Date appears wrong on repeater field and data transfer

  • Hello!

    I have two doubts.
    The first is: how do I make the field empty when there is no data in the frontend? The repeater field has entered today’s date instead of leaving empty.

    Code that I am using to display the date is as follows:

    <?php $date = get_sub_field('desde', false, false); 
    $date = new DateTime($date);?>
    <?php echo $date->format('d/m/Y'); ?>

    The other question is: there is a Repeater Field that collects information in several phases within a page (the same Repeater Field in different phases, so we can collect different information on one page, only for different phases). I now want to use the same Repeater Field, but on another page and without phases, so it is general. I would like to collect the information registered in the old Repeater Field and insert it into the new Repeater Field. It’s possible? If so, where do I collect the information that is registered in it for replication?

    Below is the code used for Repeater Field in both old and new (which remains the same, but now it is not within any phase):

    array (
    	'key' => 'field_57c8e3d4d2c8d',
    	'label' => __('Follow up','psp_projects'),
    	'name' => 'follow_up',
    	'type' => 'repeater',
    	'instructions' => 'Insira aqui as informações e detalhamento em relação a este projeto.',
    	'column_width' => '',
    	'sub_fields' => array (
    		array (
    			'key' => 'field_57c8e4f9d2c90',
    			'label' => __('Assunto','psp_projects'),
    			'name' => 'unidade',
    			'type' => 'text',
    			'column_width' => '',
    			'default_value' => '',
    			'placeholder' => '',
    			'prepend' => '',
    			'append' => '',
    			'formatting' => 'html',
    			'maxlength' => '',
    		),
    		array (
    			'key' => 'field_57c8e41bd2c8e',
    			'label' => __('Data','psp_projects'),
    			'name' => 'data_de_atualizacao',
    			'type' => 'date_picker',
    			'date_format' => 'yymmdd',
    			'display_format' => $date_format,
    			'first_day' => 1,
    		),
    	),
    'row_min' => '',
    'row_limit' => '',
    'layout' => 'row',
    'button_label' => __('Adicionar Follow up','psp_projects'),
    )

    Thank you in advance!
    I apologize for my poor English (from Google)

  • About your first question, when your “desde” field is empty, it will return the today date same way if i do this:

    $date = new DateTime();

    You should make a condition to test if $date is not empty, like:

    
    <?php $date = get_sub_field('desde', false, false); 
    if($date){
    $date = new DateTime($date);
    echo $date->format('d/m/Y'); 
    } ?>
    

    Second question…. not clear what you mean 🙂

  • Hello, @rgdesign !

    Thank you for the prompt and efficient response.
    On the first question was super sure with if $ date. Thank you!

    About the second question, it is really complicated to explain. Let’s see if I can explain myself better now:

    I created a form with some custom fields (inside a repeater), which in the frontend becomes a table, the data entered in this table is that I would like to find them, since I registered them and saved them, where I can find them to use in Another repeater? Does it exist? It’s possible? I hope I have been able to express myself better this time. 🙂

    Again, thank you very much! <3

  • aja, you need to share some fields of a repeater already created into some new field group? that´s it?

    You have a “clone” field, don´t know if it´s only available on ACFPro i only use that version, but with that “clone” field you can just do that, clone some fields into some new group.

    So, you don´t need to create a new repeater on the new field group, just create a clone one and choose the old repeater to clone. From front-end side will be almost the same thing you already have. See documentation better to understand how it works, not hard at all.

    Good luck!

  • Hi, @rgdesign!

    No. That’s not what I’m trying to do. I did exactly that “I clone” the repeater, but what I want are the data registered in them, I believe they are in the database, I do not know ..

    It is possible?

    Because I “cloned” the repeater and the information that was registered did not come together. Do you understand? It is as if nothing has been registered in it, even if the key is the same ..

    Well, I guess that’s not possible, is it?

    Thank you!

  • Yes, i understand, you need to get the values of those fields, not just clone the fields.
    May be you could export to php, take the old group with that repeater you cloned. Then include that code in your functions.php but make sure to change field/group keys, must be unique.
    On the code you will see a “location” key, you must change that to the new location, let´s say, on some page, or all pages, or a post, you know, where the field group should be placed.
    Then using similar functions you already have to build that table from the repeater fields, take the values and use as “defaults” for every field on the repeater you need to.
    Once you create a page where this new group is placed, it will get the values from the old repeater as default ones, when saved they will be saved as post meta on database.

    Now? 🙂

    Sounds good?

  • Thanks again, @rgdesign ! 🙂

    But what I did was just that.
    I’m sorry I did not explain right away in the first question.

    The code of the first question is the php that I exported from my old custom field, I used the same key in my new location and the values of the old one do not come, they are blank.

    But it’s alright. Let’s leave it like this, okay?

    Thank you very much for your efforts to help me resolve the issue.

    (I will put the first question as solved, regarding the dates, because it solved even rsrs)

    Thankfully,
    Amanda

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Date appears wrong on repeater field and data transfer’ is closed to new replies.