Jump to content

Use API to update a "select" field


nathan
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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);
  • Like 1
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

×
×
  • Create New...