Hi all,
I am writing a function triggered by cred_save_data where I have the following line:
$field1 = get_post_meta($post_id, 'wpcf-user-type', true);
It works, but because the user type it's a select field it returns the field content (ID) instead of the display text, how can I get the display text instead ?
Also, how can I get the image from a multi-image custom field (any image of the array would do) and set that one as featured image ?
thanks
Regards
Nicola
For this you will perhaps need to use the same type_render_field but this will return an array of results. From there you can pick off which one you want and use it as the featured image.
Hi Shane
thanks for your indications that possibly would solve my issue, but when I test the snippet and get whatever PHP error my site crashes and I can't even access it via FTP. I must ask my provider to delete the snippet file to get the site back. I have activated TOOLSET_CODE_SNIPPETS_TEST_MODE but I don't understand how this helps. Can you explain me how to test a snippet avoiding to crash the whole site ? the only solution I can think of is to create a local copy of the site so that I can delete the snippet code by myself.
thanks
Regards
Nicola
Hi Shane
I found an old localhost toolset site that I can use for testing the snippet. Its objective is simply to write some field contents alltogether in the excerpt field. I don't get errors anymore, but the excerpt field is empty. Could you please tell me what's wrong in this code ? thanks
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_action('cred_save_data','write_excerpt_profiles',10,2);
function write_excerpt_profiles($post_id,$form_data) {
if ($form_data['id']==20753) {
$sometext = get_post_meta($post_id, 'post_content', true);
$phone1 = types_render_field("negozio_telefono", array('item'=> $post_id ));
$phone2 = get_post_meta($post_id, 'wpcf-negozio_telefono2', true);
$excerpt= $sometext . ', ' . $phone1 . ', ' . $phone2
$args = array('ID' => $post_id, 'post_excerpt' => $excerpt);
wp_update_post($args);
}
}
Hi Shane
I managed to have the above function working with manageable errors on local copy of the site. Types_render_field works, but types_render_termmeta doesn't. I have a taxonomy called user-age with just one value selected, I cannot get the selected value with this code, could you please tell me what's wrong ? thanks, regards
How are the ids stored in the custom field? Are they stored as a comma separated list? Can you send me a screenshot of what the IDs would look like in the field ?
Hi Shane,
Q. How are the ids stored in the custom field?
actually I don't know because the variable is always empty. Ages it's a normal flat taxonomy of age ranges and users always select one only. See screenshot. I was wondering if I should change
array( 'fields' => 'ids' )
into
array( 'fields' => 'name' )
or
array( 'fields' => 'slug' )
because I don't have any field called "IDs". What I am expecting to see in return is the name of the selected age range: eg: 26-35
thanks
Nicola
actually I don't know because the variable is always empty.
There is the problem. This means that there is something wrong with the logic of how you're getting the term ids. The custom field 'user-age' is being used to store the value of the term id.
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?
Please where applicable please provide me with a link to an example page where I can see the issue.
I've enabled the private fields for your next response.
Hi Shane
could you please be more specific ? I am not a PHP programmer I am trying just to copy some code to get this done, I've lost a week already trying these two lines of code ! Honestly I don't see why Toolset doesn't have a "types_render_taxonomy" equivalent of "types_render_field" ....
I want to get the term_name. I have tried
We don't have a types_render_taxonomy function because this will essentially be redundant as the wordpress default function works with all taxonomies even custom taxonomies. Also there isn't any need for special processing.
However to make things a lot simpler you can use the taxonomy shortcode since you're not a PHP programmer.