当用户在我的 Wordress 网站上注册时,会自动创建一个自定义帖子(运动员),并将该用户指定为作者。自定义帖子本质上充当个人资料页面。
在他们的个人资料页面上,用户填写一堆或信息,然后total_score
计算并保存为用户元数据。如果他们没有填写所有表格 - 他们将不会有一个total_score
,因为它是在提交时计算的。
我为帖子(运动员)创建了一个自定义存档页面,并使用设置>阅读>帖子页面将其设置为默认帖子存档。
在发布预览模板(使用 Ele Custom Skins 和 Elementor 创建和循环)上,我添加了一个名为#total_score_circle
- 的元素,如下面的屏幕截图所示。
如果该帖子的作者元中#total_score_circle
没有,我想隐藏在帖子预览布局中。total_score
下面的代码目前隐藏了#total_score_circle
所有帖子预览,而不仅仅是total_score
作者元中不存在的那些。所以我的查询显然是关闭的。
任何帮助将不胜感激。
function total_score_display(){
if (is_home()){
global $post;
$author_id=$post->post_author;
$total_score = get_the_author_meta('total_score', $author_id);
if(empty($total_score)) : ?>
<style type="text/css">
#total_score_circle {
display: none !important;
}
</style>
<?php endif;
}
}
add_action( 'wp_head', 'total_score_display', 10, 1 );
前端是使用 Elementor Pro 创建的,我使用 Elementor Custom Skin 创建了显示搜索结果的循环。