Support

Account

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