desbest Posted November 1, 2017 Share Posted November 1, 2017 How do I get the title of a SelectOptions option, by its option id? I have this code. $options = $fieldtypes->get('FieldtypeOptions')->getOptions("experienced_in"); I do not know what to add after it and I've searched google and the processwire forum and couldn't find anything. Link to comment Share on other sites More sharing options...
wbmnfktr Posted November 1, 2017 Share Posted November 1, 2017 With your code: $options = $fieldtypes->get('FieldtypeOptions')->getOptions("experienced_in")->title; Much shorter and probably much easier in page context: $optionsId = $page->optionsfieldname; // the ID $optionsValue = $page->optionsfieldname->value; // the value $optionsTitle = $page->optionsfieldname->title; // the title 1 Link to comment Share on other sites More sharing options...
desbest Posted November 1, 2017 Author Share Posted November 1, 2017 Yes but I'm not getting the title from the current page, so I can't use the $page ones. How do I change $options = $fieldtypes->get('FieldtypeOptions')->getOptions("experienced_in")->title; to choose the ID I want, as there are multiple options and it keeps getting the first one. I want to choose a number of one of the array entries. I tried to add [0] or [1] to the line of code above, and it didn't work. Link to comment Share on other sites More sharing options...
wbmnfktr Posted November 1, 2017 Share Posted November 1, 2017 Try this: $options = $fieldtypes->get('FieldtypeOptions')->getOptions("optionsfield")->get('id=2')->title; Easier to maintain and for further use: $options = $fieldtypes->get('FieldtypeOptions')->getOptions("optionsfield"); $options->get("id=$yourId")->title; 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