Jump to content

get all field values even on following paginated pages


Recommended Posts

I have a profield table and one of its fields is called category.

I want to use the values of this field and created a unique array which I use for the options-filter.

$rows = $pages->get('path/to/parent/page')->protable;
$categories = new WireArray;
foreach ($rows as $r) :
    if ($r->category != '') :
$categories = $categories->unique();

So I loop through the $categories array and output an option field for each.

This kinda works but not with the pagination. On the second page it would only show the "options" (categories) of those entries that the unfiltered array would show on a second page.

Where's the problem?

Link to comment
Share on other sites

The problem is that $rows only holds the items of the current page, as per your pagination settings. To get all items, you need to explicitly overwrite the limit and offset resulting from your pagination settings and the current page. Then you can use that to create a complete list of categories. Something like this should work:

$rows = $pages->get('path/to/parent/page')->protable('start=0, limit=9999');
$categories = array_unique(array_filter($rows->each('category')));

Note the high limit which overrides the default limit set by the pagination. Not pretty, but I don't think it's possible to override the limit to none. Just make sure the limit is higher than the number of values you ever expect to have in your field.

  • Like 1
Link to comment
Share on other sites

Great, didn't know limit=0 would work, good to know!

You don't need the second row, just a less verbose and error-prone alternative to the procedural code in your initial post 🙂
I prefer this functional style, but in the end, it doesn't even matter.

  • Like 1
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

  • Create New...