In several previous queries, e.g., change footnotes to endnotes, but allow some old footnotes I asked about converting footnotes to endnotes in a flexible way that didn't involve changing the actual \footnote{} commands to \endnote{} in the text. I found a satisfactory solution, in the code below, that I include as input{endnotes} in my main book file, shown below with references to previous discussion on this topic.
However, after the last chapter, once \backmatter has been seen, I still get spurious Chapter Notes pages for each chapter-like unit (Bibliography, Author Index, Subject Index). How can I suppress these?
I admit that I don't fully understand the logic of this solution, but an answer to my current question has to do with the line \pretocmd{\backmatter}{\printnotes*}{}{}%
endnotes.tex
% Change footnotes to endnotes
% https://tex.stackexchange.com/questions/56145/is-there-a-way-to-move-all-footnotes-to-the-end-of-the-document
% https://tex.stackexchange.com/questions/399527/change-footnotes-to-endnotes-but-allow-some-old-footnotes
\usepackage{pagenote}
\let\oldfootnote\footnote
\renewcommand{\FN}[1]{\oldfootnote{#1}}
\renewcommand{\thefootnote}{\alph{footnote}}
\makepagenote
\let\footnote\pagenote
% For endnotes at end of each chapter or at the very end of mainmatter
% https://tex.stackexchange.com/questions/83815/how-to-renew-chapter-command-to-include-endnotes-i-e-printnotes
\usepackage{etoolbox}
\newtoggle{chapternotes}
\toggletrue{chapternotes}
%\togglefalse{chapternotes}
\iftoggle{chapternotes}{%
% using chapternotes
\renewcommand{\notedivision}{\section*{\notesname\ to Chapter~\thechapter}}%
\renewcommand{\pagenotesubhead}[2]{}%
% \pretocmd{\chapter}{\printnotes*}{}{}%
\pretocmd{\chapter}{%
\ifnum\value{chapter}>0\relax\printnotes*\fi%
}{}{}
\pretocmd{\mainmatter}{\printnotes*}{}{}% Notes in Preface
\pretocmd{\backmatter}{\printnotes*}{}{}%
}{%
% using notes at end of book
\renewcommand{\notedivision}{\chapter*{\notesname}}
}

\let\oldfootnote=\footnotefirst. When you want to go back,\let\footnote=\oldfootnote. (the=is optional) – John Kormylo Oct 20 '18 at 16:06\backmatter– user101089 Oct 21 '18 at 14:19