adinuno Posted November 1, 2013 Share Posted November 1, 2013 Hi there, I am struggling with a very simple variable. I'm using the following function to get the url of a certain child: <?php echo $page->find("projects")->url ?> But it returns an error: Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Selectors.php line 165) #0 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Selectors.php(190): Selectors->create('projects', '', '') #1 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Selectors.php(63): Selectors->extractString('has_parent=1, p...') #2 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Pages.php(143): Selectors->__construct('has_parent=1, p...') #3 [internal function]: Pages->___find('has_parent=1, p...', Array) #4 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Wire.php(271): call_user_func_array(Array, Array) #5 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Wire.php(229): Wire->runHooks('find', Array) #6 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Page.php(786): Wire->__call('find', Array) #7 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Page.php(786): Pages->find('has_parent=1, p...', Array) #8 /Applications/XAMPP/xa This error message was shown because you are logged in as a Superuser. Error has been logged. The page called 'projects' exists, what could be the problem? Thanks in advance Link to comment Share on other sites More sharing options...
adrian Posted November 1, 2013 Share Posted November 1, 2013 Try this: <?php echo $page->find("name=projects")->url ?> or you can use the path of the page, eg. if it is at the root of you site you can do: <?php echo $page->find("/projects/")->url ?> Also, be sure to install the selector test module - will help you figure out the right selector more easily: http://modules.processwire.com/modules/process-selector-test/ EDIT: Be sure to take nik's advice below about get vs find! 1 Link to comment Share on other sites More sharing options...
nik Posted November 1, 2013 Share Posted November 1, 2013 Hi Gespinha, ProcessWire is trying to tell you that "projects" is not a valid selector. See http://processwire.com/api/selectors/ on how to write selectors, this being the key here: "An individual selector consists of three parts: the field you are looking for, an operator (like an equals '=' sign), and the value you want to match. For example, a basic selector might be: title=products". So you could use for example "name=products". But just fixing the selector is not enough here; you're using find() which returns a PageArray (even if there's just one match), not a single Page. If you're trying to get a specific page, you could use get() instead. It works like find() but returns only the first match (a Page object). Or you could say find()->first()->url to access the first found Page inside the returned PageArray. 4 Link to comment Share on other sites More sharing options...
adinuno Posted November 1, 2013 Author Share Posted November 1, 2013 Thanks guys, you have, once again, solved the problem 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