Manaus Posted November 7, 2021 Share Posted November 7, 2021 Hello, I don't grasp the use of a selector like $fields->get("name") or $fields->find("selector") I see in the cheatsheet, since when I need to print a custom field from the page I just need to write $page->mycustomfield or similar. How can I use the $fields object? Thanks! Link to comment Share on other sites More sharing options...
kongondo Posted November 7, 2021 Share Posted November 7, 2021 (edited) 46 minutes ago, Manaus said: How can I use the $fields object? There's lots of use cases mainly related to module development as well as internal ProcessWire use. You can also use it (with caution) for housekeeping. Let's say you created a number of fields for testing purposes on a site or module you are working on. You gave your fields a specific prefix to easily identify them as test fields, for instance. You now want to delete them. They are not in use in any template. There are a lot of them. Instead of deleting them manually, you can use the API to do it for you. <?php namespace ProcessWire; // get your 'test' fields // their names start with 'test', e.g. 'test_some_field' $testFields = $fields->find("name^=test"); d($testFields,'TEST FIELDS'); foreach($testFields as $testField){ $fields->delete($testField); } Run that in Tracy console and you are done. Edited November 7, 2021 by kongondo typos 3 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