Skip Navigation

[Resolved] I want to update a repeater custom field using php

This support ticket is created 4 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 4 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1443377

Tell us what you are trying to do?
I have created a single line repeater custom field that I want to use as a changelog. What I want is update the custom field by adding a new line from php.

Is there any documentation that you are following?

I usually do somehting like this to update a custom field and it works, but in the case of this repeated field it seems that I need to do something different and I could'nt find any documentation on your website regarding that:

$my_post = array(
'ID' =>23,
'wpcf-change-log' => "new text for the changelog",
);
// Update the post into the database
wp_update_post( $my_post );

What is the link to your site?
hidden link

#1443815

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand - you want to add new instance with value for repeating field. If this is correct, you should use the add_post_meta() method.

For example:

$post_id = 23;
add_post_meta( $post_id , 'wpcf-change-log', "new text for the changelog");
#1445165
toolset-support.PNG

That is what I want, I uploaded a screenshot just to make sure we are talking about the same thing.

I basically want to add a new entry with php, like doing a click in that "Add new" button" but with php. LoL

I'm currently using:
update_post_meta($post_id, 'wpcf-change-log', 'new text for the changelog');
And it updates the first entry, I'm using this because I need to have something working... but that is not my ideal solution.

I tried your example(with my own variables):
add_post_meta( $post_id , 'wpcf-change-log', "new text for the changelog");
but nothing happens.

Does my screenshot help? or are we talking about the same thing and it's something else in my code what causes the problem.

#1445675

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It should work. Can you please tell me exactly when you would like to add the new value using add_post_meta( $post_id , 'wpcf-change-log', "new text for the changelog");?

Can you please share access details so I can review the things and share the details when exactly you would like to add the new value. Problem URL with an explanation would help.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.