I have this function in a wordpress site:
function cf7_get_custom_field($atts){
extract(shortcode_atts(array(
'key' => '',
'post_id' => -1,
'obfuscate' => 'off'
), $atts));
if($post_id < 0){
global $post;
if(isset($post)) $post_id = $post->ID;
}
if($post_id < 0 || empty($key)) return '';
$val = get_post_meta($post_id, $key, true);
if($obfuscate == 'on'){
$val = cf7dtx_obfuscate($val);
}
return $val;`
The return $val gives the post ID number, but instead I would like it to be the post title.
The line:
$val = get_post_meta($post_id, $key, true);
Should have get_post_title or get_title in there somewhere, I suppose.
Any tips?
You can use
get_the_title
which returns the title of the post based on the post ID number.