@hube2 John,
your solution gave me right direction !!
for anyone looking for the same or similiar solution here is the code
add_filter('post_thumbnail_id', 'replace_thumbnail_id_with_acf', 20, 2);
function replace_thumbnail_id_with_acf($thumbnail_id, $post) {
if ( is_user_logged_in() ) {
$image_id = get_field('reveal_face', $post->ID, false);
if ($image_id) {
$thumbnail_id = $image_id;
}
} else {
$image_id = get_field('_thumbnail_id', $post->ID, false);
if ($image_id) {
$thumbnail_id = $image_id;
}
}
return $thumbnail_id;
}
John, Im not quite sure if I understand
I do have 2 fields
1. with name “_thumbnail_id” with which I can set the default featured image of a post.
– which i found as a comment on this forum provided by you – thanks again
2. with name “main_image_logged” where the image which can be seen only by logged in users.
@hube2 thank alot !
small question, when my field name is _thumbnail_id
can i still get it by using get_field(‘_thumbnail_id’,..) ?
I tried something like this
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);
but its wrong
Thank you John,
any idea of a possible workaround how to get it done with ACF ? without using the native WP thumbnails ?
in any case thank you for your time
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.