ACF - 根据用户状态更改帖子特色图像
我创建了一个名为“main_image”的字段组,在它下面有 2 个字段 1. '主图像记录' 类型:图像
2。 'main_image_logout' type:image
我想做的是向所有人显示帖子附带的经典特色图像,并为
登录的用户在“main_image_logged”字段中显示图像以进行注销,我什至尝试设置 name:_thumbnail_id从“main_image_logout”获取图像并将其用作特色图像。
有什么办法可以做到这一点吗? 如果用户已注销->来自“main_image_logout”字段的特色图像 如果用户已登录->来自字段“main_image_logged”的特色图像
尝试了类似的操作,但
function acf_set_featured_image( $value, $post_id, $field ){
if (is_user_logged_in()) {
if($value != ''){
//Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_post_meta($post_id, '_thumbnail_id', $value);
}
return $value;
}
}
add_filter('acf/update_value/name=main_image_logged', 'acf_set_featured_image', 10, 3);
使用时是错误的: WordPress 高级自定义字段 Divi主题
非常感谢大家
I’ve created a field group called ‘main_image’ and under it I have 2 fields
1.
‘main_image_logged’
type: image
2.
‘main_image_logout’
type:image
what im trying to do is to show the classic featured image which comes with the post for all, and for users that is logged in show the image in field “main_image_logged’
for the logout i even tried to set name:_thumbnail_id which took the image from ‘main_image_logout’ and used it as a featured image.
is there any way how to do this?
if user is logged out -> featured image from field ‘main_image_logout’
if user is logged in -> featured image from field ‘main_image_logged’
tried something like this but it's wrong
function acf_set_featured_image( $value, $post_id, $field ){
if (is_user_logged_in()) {
if($value != ''){
//Add the value which is the image ID to the _thumbnail_id meta data for the current post
add_post_meta($post_id, '_thumbnail_id', $value);
}
return $value;
}
}
add_filter('acf/update_value/name=main_image_logged', 'acf_set_featured_image', 10, 3);
using:
Wordpress
Advanced custom fields
Divi theme
thanks alot guys
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
Try this