Jump to content

Populating a PageReference multi-select field via the API


cjx2240
 Share

Recommended Posts

How might I populate a page reference multi-select field (with options limited to pages of a specific parent) using the API? I'm doing some manual data importing and I have some categories in json like this (which came from the first-party Export/Import module)

"categories": [
                    "/categories/dance/",
                    "/categories/film/",
                    "/categories/poetry/"
                ],

The pages are all set up correctly on the source site, with the same names

I've done images, repeaters etc, but I'm not clear on the syntax for populating a pagereference field. Something like

$page->categories->add($category);

(Where category is that path from the loop) Is what I was hoping for

Link to comment
Share on other sites

As is so often the case from the magic of rubber duck programming, I realised that $category needs to be the page I've made. While ProcessPageExportImport probably does something clever with those paths, in my case I needed

$page->categories->add($pages->get("path=$category"));

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...