nathan Posted January 21, 2016 Posted January 21, 2016 I have a page that has a field that contains a page. How do I use the API to update a page select field in the page's page? Example: User page has field "member" which points to a member page. Member page has field "gender" which points to page for selecting gender. How do I change the page the gender points to from the user page? I've tried $user->member->gender = 123; where 123 is the new page ID. Also, $user->member->set("gender", 123); Both of these seem not to work.
adrian Posted January 21, 2016 Posted January 21, 2016 This works for me: $user->of(false); $user->member->gender = 123; $user->member->save("gender"); EDIT: or for something even simpler using the new method introduced in 2.6.9 (https://processwire.com/blog/posts/processwire-2.6.9-core-updates-and-new-procache-version/#new-page-gt-setandsave-method): $user->member->setAndSave('gender', 123); 1
LostKobrakai Posted January 21, 2016 Posted January 21, 2016 As adrian's answer shows you'll need to save the member page, not the user. The user page just holds the reference to the member page, but the fielddata of both pages are fully unrelated to one another. 1
nathan Posted January 21, 2016 Author Posted January 21, 2016 Ah yes, now it works. I didn't realize you had to save the other page. Thanks! 1
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