首页 > 解决方案 > Wordpress 用户条件标签

问题描述

我怎样才能使wordpress用户条件标签像这样

<?php if (current user has fill first_name field()){ ?>
your info is complete
<?php } else { ?>
you need to fill first_name field
<?php } ?>

请帮助我,谢谢

标签: wordpressif-statementtagsconditional-statements

解决方案


您可以使用get_the_author_meta()函数获取用户元数据并get_current_user_id()获取当前用户 ID。

<?php
if ( get_the_author_meta( 'user_firstname', get_current_user_id() ) ) {
    echo 'your info is complete';
} else {
    echo 'you need to fill first_name field';
}

参考:get_the_author_meta() get_current_user_id()


推荐阅读