我还没有测试过这个,但你可以试试这个:
将此php放入函数中。php。
function rt_connections_id () {
if ( is_user_logged_in() ) {
$usersid = get_current_user_id();
$newout = do_shortcode(\' [connections id=\'.$usersid.\'] \');
} else {
$newout = \'\';
}
return $newout;
}
add_shortcode(\'current-user-connections\', \'rt_connections_id\');
现在使用短代码将其付诸实施
[current-user-connections]
而不是
[connections id=1]
.
UDPATE基于评论。。。我对您使用的插件一无所知,但如果您需要查询用户元,我会将上述代码更改为:
function rt_connections_id () {
if ( is_user_logged_in() ) {
$usersid = get_current_user_id();
$entryid = get_user_meta( $usersid, \'connections_entry_id\', true );
$newout = do_shortcode(\' [connections id=\'.$entryid.\'] \');
} else {
$newout = \'\';
}
return $newout;
}
add_shortcode(\'current-user-connections\', \'rt_connections_id\');
我在这里没有做任何错误处理来测试
connections_entry_id
是空的,我还假设它是一个单条目字符串。
最后,如果它位于数组中,请尝试以下操作:
function rt_connections_id () {
if ( is_user_logged_in() ) {
$usersid = get_current_user_id();
$usermeta = get_user_meta($usersid);
$entryid = $usermeta[\'connections_entry_id\'][0];
$newout = do_shortcode(\' [connections id=\'.$entryid.\'] \');
} else {
$newout = \'\';
}
return $newout;
}
add_shortcode(\'current-user-connections\', \'rt_connections_id\');
以下是一些错误更正:
function rt_connections_id () {
if ( is_user_logged_in() ) {
$usersid = get_current_user_id();
$usermeta = get_user_meta($usersid);
$entryid = $usermeta[\'connections_entry_id\'][0];
if ( ! empty( $entryid ) ) {
$newout = do_shortcode(\' [connections id=\'.$entryid.\'] \');
} else {
$newout = do_shortcode(\' [connections_link_view text_add="Add My Entry"] \');
}
} else {
$newout = \'\';
}
return $newout;
}
add_shortcode(\'current-user-connections\', \'rt_connections_id\');