maddmac 9 Posted February 26 Is there a method to programmatically select pages from a PageSelect based on the name of the page and associate them? I want to pass an array of page names or a comma separated list. These page names would be looped through and then added as multi page select for a specific field. These are existing pages not new pages. It's too cumbersome to manually select multiple pages Share this post Link to post Share on other sites
bernhard 5,295 Posted February 28 I don't understand your question. Examples are always a good idea 😉 1 Share this post Link to post Share on other sites
maddmac 9 Posted March 1 @bernhard no problem. I have a list of child pages that I want to associate with a page. For example I have a particular author that I want to programmatically associate book titles (pages) with an author what would be the best way of doing this programmatically without manually associating pages by the book title name? I can easily create a comma separated list of the books per Author name. Douglas Adams (author-page) These are all books (pages) The Hitchhiker's Guide to the Galaxy Life, the Universe and Everything (Hitchhiker's Guide to the Galaxy, #3) Book title 3 Book title 4 Share this post Link to post Share on other sites
bernhard 5,295 Posted March 1 Sorry, I don't get what you mean by "programmatically" and I don't get your example. Maybe others can help 🙂 1 Share this post Link to post Share on other sites
Jan Romero 491 Posted March 1 If you have a single page reference field called “author” on book pages (would probably recommend this way, even if you allow multiple authors per book): $book = $pages->get('template=book, title="The Hitchhiker’s Guide To The Galaxy"'); $author = $pages->get('template=author, title=Douglas Adams'); $book->of(false); $book->author = $author; $book->save(); If you have a multi page field called “books” on author pages: $author = $pages->get('title=Douglas Adams'); $books = $pages->find('title="The Hitchhiker’s Guide To The Galaxy"|"Life, the Universe and Everything"'); $author->of(false); foreach ($books as $book) $author->books->add($book); $author->save(); 1 Share this post Link to post Share on other sites
maddmac 9 Posted March 1 Thanks @Jan Romero This method seems to be much easier then I thought it would be Share this post Link to post Share on other sites