maddmac Posted February 26, 2021 Share Posted February 26, 2021 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 Link to comment Share on other sites More sharing options...
bernhard Posted February 28, 2021 Share Posted February 28, 2021 I don't understand your question. Examples are always a good idea ? 1 Link to comment Share on other sites More sharing options...
maddmac Posted March 1, 2021 Author Share Posted March 1, 2021 @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 Link to comment Share on other sites More sharing options...
bernhard Posted March 1, 2021 Share Posted March 1, 2021 Sorry, I don't get what you mean by "programmatically" and I don't get your example. Maybe others can help ? 1 Link to comment Share on other sites More sharing options...
Jan Romero Posted March 1, 2021 Share Posted March 1, 2021 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 Link to comment Share on other sites More sharing options...
maddmac Posted March 1, 2021 Author Share Posted March 1, 2021 Thanks @Jan Romero This method seems to be much easier then I thought it would be Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now