Valery Posted February 5, 2013 Share Posted February 5, 2013 Hello, everybody, I am trying to display the number of published articles per author. echo $wire->pages->find("author~=Sam Smith").getTotal(); PW says: Error Call to undefined function getTotal() However, the function is in the Cheatsheet. And second: why does echo $wire->pages->find("author~=Sam Smith").count(); give me "1001|1002" instead of the number of found pages? What's the correct way to count a PageArray size? Thanks for any help with that. Link to comment Share on other sites More sharing options...
Soma Posted February 5, 2013 Share Posted February 5, 2013 ->getTotal() not .getTotal(). 2 Link to comment Share on other sites More sharing options...
Valery Posted February 5, 2013 Author Share Posted February 5, 2013 Thanks, Soma. My bad, sorry. Everything's working now. Link to comment Share on other sites More sharing options...
Soma Posted February 5, 2013 Share Posted February 5, 2013 echo $wire->pages->find("author~=Sam Smith") Doing echo on a page array, this will output id's separated with a pipe. This is using a toString method that is for convenience if you use the result in a other selector it will get inserted as string as 1929|1293|1231. Which is handy. Otherwise it will be a page array you can further use. For example: $found = $wire->pages->find("somefield*=anyword"); $result = $wire->pages->find("selected_authors=$found"); Which will result behind the scenes as something like this: $result = $wire->pages->find("selected_authors=1928|1233|1234"); Where selected_pages would be a page field for example. If you just really need the count of a find you can also just use count instead. $count = $pages->count("authors*=John"); Which is more efficient than a find. 5 Link to comment Share on other sites More sharing options...
Valery Posted February 5, 2013 Author Share Posted February 5, 2013 Thanks for the insight. Really appreciate your help with finding and counting vs just counting. Handy! Link to comment Share on other sites More sharing options...
ryan Posted February 5, 2013 Share Posted February 5, 2013 Definitely use the $pages->count() as Soma mentioned. If you are dealing with a large quantity of pages, and all you need is the count, it is much faster, since it doesn't have to load those pages. Link to comment Share on other sites More sharing options...
Martijn Geerts Posted February 5, 2013 Share Posted February 5, 2013 Didn't know that was possible Soma... tnx 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