make sure a slug is generated on publish and fix some notices

I would use double-quote strings to avoid having to add slashes to the single quotes. Or use double quotes in the sql.