hi utilibre,
Types prepend “wpcf-” before your custom field slug,
Please try like this:
$key = 'custom';
if (get_post_meta($post->ID, 'wpcf-' . $key, true) == 2){
do something here...
}
Hi wdisk, yes i know the wpcf code but my issue is the integration of the code. In my case, it is wpcf-premium. So would you know where i should add the below code and is the code right?
$key = ‘custom’;
if (get_post_meta($post->ID, ‘wpcf-premium’ . $key, true) == 2){
echo (-icon-url-)
}
I understand you want to append the icon to the title. In this case, you need to setup a filter that changes the title, like this:
add_filter('the_title', 'add_icon_to_title', 10, 2);
function add_icon_to_title( $title, $post_id ) {
if ( get_post_meta( $post_id, 'wpcf-premium', true ) == 2 ) {
$title = 'ICON ' . $title;
}
return $title;
}
Thanks Caridad, I added below to the child theme’s function but no luck (no changes):
/*add icon to the title*/
add_filter('the_title', 'add_icon_to_title', 10, 2);
function add_icon_to_title( $title, $post_id ) {
if ( get_post_meta( $post_id, 'wpcf-type', true ) == 2 ) {
$title = 'http://s1.wsj.net/img/icon_key.png' . $title;
}
return $title;
};
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
*I put the icon image address of wsj as example
You need to add the whole HTML tag, not just the URL:
add_filter('the_title', 'add_icon_to_title', 10, 2);
function add_icon_to_title( $title, $post_id ) {
if ( get_post_meta( $post_id, 'wpcf-type', true ) == 2 ) {
$title = '<img src="http://s1.wsj.net/img/icon_key.png"> ' . $title;
}
return $title;
};
Make sure you place the code between the PHP tags in the functions.php file of your theme.
still no luck. What is that “10” and “2” for?
10 is the priority. You may try using a higher number.
2 is the number of parameters that the function will receive, leave that one as it is.
You have more information over here:
http://codex.wordpress.org/Function_Reference/add_filter
sorry but still no luck, i changed 10 to 20 but no see no changes.
I also added php codes but no luck. 🙁
Have you enabled WP_DEBUG in your wp-config.php file? There might be an error message there that explain why this happens.
yes tried it but it doesn’t give any errors at all
Do you mind opening a support thread in our website?
You can share your credentials there so we can review whats wrong.
http://wp-types.com/forums/forum/general-and-pre-sales-questions/
no problem, i just created an account and added the info there.
All, thanks to types admin, Adriano, and Caridad for this”
Apparently, I had to type the value name for the second one. This is how I fixed it:
add_filter(‘the_title’, ‘add_icon_to_title’, 10, 2);
function add_icon_to_title( $title, $post_id ) {
if ( get_post_meta( $post_id, ‘wpcf-type’, true ) == premium ) {
$title = ‘<img src=”http://s1.wsj.net/img/icon_key.png”> ‘ . $title;
}
return $title;
};