Fix for wrong author id due to multiple records with the same $pk

Also fix undefined $pk variable notice.