Jump to content

getTotal() is "undefined"


Valery
 Share

Recommended Posts

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

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.

  • Like 5
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...