Skip Navigation

[Resolved] Auto insert or save value custom field (re-open ticket)

This support ticket is created 5 years, 3 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 11 replies, has 3 voices.

Last updated by Shane 5 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#1339505
1335329-Schermafdruk_2019_09_09_16.24.15.png

Hi Shane,

I didn't noticed the closed status of ticket: https://toolset.com/forums/topic/auto-insert-or-save-value-custom-field/

Sorry wasn't able to respond for a while. Thanks a lot. Unfortunately the script throws an error like shown in the image. According to Google this could be due to an old PHP version (below 7.x) on my webserver. I have checked and it 7.3.5, so this seems to be oke. What should I do?

Thanks.

#1339535

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Jelle

I didn't read through the whole of the prior ticket to know quite what the intention is here, but I can see a simple error in the code that means it is broken, namely the double quotes wrapping the anchor tag are being broken by double quotes within the anchor tag, so at a minimum you would need to convert the inner double quotes to single quotes, like so:

function update_my_post( $post_id ) {
 
update_post_meta($post_id,"wpcf-sku","<a href='/datasheet/?product_id=[wpv-post-id id='$parent']&variation_id=[wpv-post-id]' target='_blank'>[woo_sku]</a>");
}
add_action( 'save_post', 'update_my_post' );

I don't recognise what the code is trying to do, so I can't say that it will work, so let me assign this ticket to Shane where you can continue the discussion if required.

#1339749

Hi Nigel,

Correct, I should use single quotes if WP All Import would let me use these, which isn't the case. That's why we've altered the code. But is seems like the dollar sign isn't accepted when importing as well unfortunately. Thanks for passing it on to Shane.

Thanks.

#1339877

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jelle,

As mentioned previously I cannot guarantee that this will work because it was based on the information from the import plugin team.

Based on that then I assume that the hook should fire.

To make this more specific could you ask them to show you an example of how to use the save post hook in order to modify each post while they are being imported?

I found and example usage here
hidden link

However it doesn't provide much information on how to modify the post custom fields with the save post hook.

If we can get an example of this then we should be able to get this code to modify the custom fields while its being imported.

Thanks,
Shane

#1341299

Hi Shane,

Thanks. I will reach out to them for an example and will let you know when they reply.

Best, Jelle

#1341373

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Thank Jelle,

Looking forward to your response.

#1343137

Hi Shane,

Below the reply I received from WP All Import support. Please see the links below. I’m not sure if this is what we need?

Here's the hook to use and there are some examples at the linked page: pmxi_saved_post

However, that fires after the post is saved.

If you need to only modify custom fields before they're saved then use this one instead: pmxi_custom_field

Let us know if you have any other questions.

hidden link

hidden link

#1343255

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jelle,

Yes this is an example I can use.


function custom_field_append( $id ) {
  
update_post_meta($id,"wpcf-sku","<a href='/datasheet/?product_id=[wpv-post-id id='$parent']&variation_id=[wpv-post-id]' target='_blank'>[woo_sku]</a>");
}
add_action('pmxi_saved_post', 'custom_field_append', 10, 1);

This one should work now based on the examples they have provided.

Thanks,
Shane

#1344425

Hi Shane,

Thanks a lot. Should it work on post update as well or only for new records? I tried it but it doesn't update records, sorry.

Thanks, Jelle

#1344515

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jelle,

This should work only for the imported posts.

However given that it doesn't work I would highly recommend discussing this with their team to see if they can figure why its not work.

I've followed their hook and only added the line that is meant to modify the post field so i'm not sure what else to actually do at this point because all you should need to do is update the fields with these values.

Thanks,
Shane

#1346967

Hi Shane,

Thanks. I have contacted WP All Import and it looks like the hook isn't firing. So I have created a ticket at their website and get back to you if needed. Thanks.

Jelle

#1347301

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jelle,

No problem. Please keep me posted on how I can assist.

Thanks,
Shane