I have a custom post type called "Cars" that I am importing from a feed, so this insert is done only on the backend, no CRED form or anything.
I have created a custom field called "Company". I want to set the featured image (or some custom image field) to a specific URL if the Company field value is equal to "Company A" and to a different URL if the Company field value is equal to "Company B".
Any thoughts how I could set this up for inserts?
Hello,
There isn't such kind of built-in feature, it depends on the plugin you "importing from feed".
If that plugin can trigger WordPress built-in action hook "save_post", you can use it to setup your custom codes and set custom fields as what you want.
More help:
https://developer.wordpress.org/reference/hooks/save_post/
Yea I was seeing that. I am still new at WP action hooks in PHP. I was hoping to translate what I know in other systems/languages into WP. For example, some sort of business rule that I can implement that "On insert of a specific custom post type, add data to this field".
For example, is something like the code below going to trigger on insert of a new custom post type called "automobiles"?
function my_save_meta_function( $post_id, $post, $update )
{
if ( get_post_type( $post_id ) !== 'automobiles' ) return;
update_post_meta( $post_id, 'wpcf-model', 'Mustang' );
}
add_action( 'save_post', 'my_save_meta_function', 99, 3 );
As I mentioned above, it depends on the plugin "importing from feed" you are using.
I am not sure if it can trigger WordPress built-in action hook "save_post", you will need to check the plugin author of "importing from feed".
In Toolset side, if the custom field is created with Toolset Types plugin, you just need to add "wpcf-" prefix before the field slug. See our document:
https://toolset.com/documentation/customizing-sites-using-php/functions/
when you are accessing custom fields through native WordPress functions, you need to prepend the wpcf- prefix to the slug. Continuing from the above example, for native WordPress function to access the “House Price” field, you need to use the wpcf-house-price slug.