最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - Creating a shortcode by pulling in a custom field from a plugin

programmeradmin0浏览0评论

I have this shortcode code:

add_shortcode( 'dashtest', function () {

$stringtest = "This is $wpc_cf_scorp";
    echo $stringtest;
} );

It is attempting to pull in a custom field created by a plugin - I've been fiddling with this, but can't seem wrap my head around it - is there a special way to call in a custom field from a plugin to a shortcode? Thanks!

I have this shortcode code:

add_shortcode( 'dashtest', function () {

$stringtest = "This is $wpc_cf_scorp";
    echo $stringtest;
} );

It is attempting to pull in a custom field created by a plugin - I've been fiddling with this, but can't seem wrap my head around it - is there a special way to call in a custom field from a plugin to a shortcode? Thanks!

Share Improve this question asked Oct 10, 2020 at 11:00 benjamin georgebenjamin george 112 bronze badges 5
  • In your callback function, you doesn't seem to be fetching any custom field. Variable $wpc_cf_scorp seems undefined. – Ankit Commented Oct 10, 2020 at 14:53
  • thanks! That sent me to what feels a bit closer, but I can't seem to figure out how to pull in a custom user field would this be something in get_user_meta() ? – benjamin george Commented Oct 10, 2020 at 15:30
  • Yes you can use get_user_meta to fetch custom user related field – Ankit Commented Oct 10, 2020 at 15:33
  • Thanks for the help! – benjamin george Commented Oct 10, 2020 at 15:43
  • figured it out :) – benjamin george Commented Oct 10, 2020 at 16:01
Add a comment  | 

1 Answer 1

Reset to default 1
add_shortcode( 'dashtest', function () {
$user_id = get_current_user_id();

  $key = 'user_wpc';
  $single = true;
  $user_last = get_user_meta( $user_id, $key, $single ); 
    

if ($user_id == 0) {
    echo 'You are currently not logged in.';
} else {
    echo do_shortcode('[userwpcode key="'.$user_last.'/edit"]');
}
} );
发布评论

评论列表(0)

  1. 暂无评论