OpenBayou Posted January 12, 2017 Share Posted January 12, 2017 Hello, I need help with the options field, I looked online and the examples have confused me. I have a drop-down option called 'deals_store' and it has three selections to choose from: 1,2,3. How do I check if the page has a field called 'deals_store' and the option is 1? This is what I've done so far: <?php if ($page->deals_store = '1'):?> show <?php else:?> hidden <?php endif;?> Thanks. Link to comment Share on other sites More sharing options...
OpenBayou Posted January 12, 2017 Author Share Posted January 12, 2017 Update: I was able to print the option that was selected but I still need some minor help. <?php foreach($pages->find("parent=deals") as $child) { ?> <?php echo $child->deals_store->title;?> <?php } ?> I have three options as of now to select: 1=option A 2=option B 3=option C <?php echo $child->deals_store->title?> For example: If I have a page with '2' selected, the above code will print the option that's selected: 'option B'. Instead of showing the title, I would like to show the number '2' instead of the title 'option B'. Thanks again for the help. Link to comment Share on other sites More sharing options...
OpenBayou Posted January 12, 2017 Author Share Posted January 12, 2017 <?php echo $child->deals_store->id?> That did it! Link to comment Share on other sites More sharing options...
kixe Posted January 12, 2017 Share Posted January 12, 2017 For the sake of completeness assuming the following fieldsettings under details tab1=title echo $child->deals_store; // print the id as string var_dump($child->deals_store->id); // int(1) var_dump($child->deals_store->sort); // int(0) var_dump($child->deals_store->value); // string(0) "" var_dump($child->deals_store->title); // string(5) "title" using the option to add a value beside the id you can use the following setup1=value|title var_dump($child->deals_store->value); // string(5) "value" for validation please keep in mind var_dump($child->deals_store == '1'); // bool(true) var_dump($child->deals_store == 1); // Notice: Object of class ProcessWire\SelectableOptionArray could not be converted to int if ($child->deals_store == '1') { // do something } Link to comment Share on other sites More sharing options...
kixe Posted January 12, 2017 Share Posted January 12, 2017 7 hours ago, OpenBayou said: <?php if ($page->deals_store = '1'):?> Your if statement use an assignment operator (=) instead of a comparison operator (==). 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