Home › Forums › Backend Issues (wp-admin) › Change post featured image based on user status › Reply To: Change post featured image based on user status
As I said, a post can only have one “_thumbnail_id”. I did some looking and it appears that all thumbnail function eventually call get_post_thumbnail_id() and like I said, the value returned can be filtered.
add_filter('post_thumbnail_id', 'replace_thumbnail_id_with_acf', 20, 2);
function replace_thumbnail_id_with_acf($thumbnail_id, $post) {
$user_id_associated_with_post = /*you need to figure this out*/;
// I don't have the condition here.
// figuring out if some user on the site is logged in
// when it is not the current user
// is a complicated process
// this is not something that WP will provide
if (/*is the user associated with this post logged in?*/) {
$image_id = get_field('image_when_logged_id', $post->ID, false);
if ($image_id) {
$thumbnail_id = $image_id;
}
} else {
$image_id = get_field('image_when_logged_out', $post->ID, false);
if ($image_id) {
$thumbnail_id = $image_id;
}
}
return $thumbnail_id;
}
As far as figuring out if the user that is associated with the given post is logged in or logged out, I found this: https://wordpress.stackexchange.com/questions/34429/how-to-check-if-a-user-not-current-user-is-logged-in
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’re working hard on Advanced Custom Fields PRO 6.0, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) August 12, 2022
Featuring improved performance for Repeater fields with large datasets, and a new generation of ACF Blocks.
Let’s take a look 🧵https://t.co/Befre3kFAo
© 2022 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.