My code is working in preview, but no working when published.

  1. Check DATABASE-PERMISSIONS.
  2. Check if you have synced your PREVIEW and LIVE-DBs.