Skip Navigation

[Resolved] Is there any way to save a value from a types custom field to a protected field?

This support ticket is created 3 years, 11 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 geophray 3 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1587791

Tell us what you are trying to do?
I'm trying to set the value of yoasts canonical url field (_yoast_wpseo_canonical) to a value stored in a types custom URL field associated with that post if it exists.

Is there any documentation that you are following?
I have not really been able to find much of anything about this problem... which makes me think there is not really a way around it. I know this is probably outside the scope of your support offerings, but you guys are brilliant so I just thought I would pose the question in case one of you had knowledge of how to edit the value of a field with an _ preceding it programatically.

Is there a similar example that we can see?
I have written the following function to try and update it, and it works if I update any other field that doesn't have an underscore in front of it.

function jmc_update_yoast_canonical( $post_id ) {
  $orig_link = get_post_meta( $post_id, "wpcf-original-article", true );
  if ($orig_link) {
    update_post_meta( $post_id, '_yoast_wpseo_canonical', $orig_link );
  }
}
add_action( 'save_post', 'jmc_update_yoast_canonical', 20, 1 );

Again... not looking for any detailed response on this. More just curious if you know if this is even possible?

#1587843

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

The code you shared seems OK to me and as you said it works as well but I do not understand exactly what is the issue yet.

You said:
I have written the following function to try and update it, and it works if I update any other field that doesn't have an underscore in front of it.
==>
Do you want to run that code on specific action? Can you please clarify more details.

#1593287

Hi Minesh,

Thanks so much for your reply. I'm sorry I was not more clear. I want that code to run when a post is updated, which it is. The problem is that the _yoast_wpseo_canonical field never accepts the data because it is a protected field. I was trying to keep all the fields our post editors would need encapsulated in a single section, which is why I wanted this custom URL field to update the _yoast_wpseo_canonical field on save, but at this point I would settle for just being able to insert the yoast field into my content template instead. That may be the easier route. I'm going to try that now and will report back on how it goes.

#1593293

Going the other direction seems to have worked. I should have done that from the start. Thanks so much for your time!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.