Reply To: Iterating through unique

Author Replies
traversal # Posted on August 1, 2014 at 11:05 am

Hey there. Certainly using the value method is the right way to go, as using the “field” method returns you an object, which will indeed always be unique.

There is one alternative way to do this however.

Assuming your store was a post type, and that your field set was called “address”, try something like this:

The $wf->stores call will give you a collection of store posts, which I’ve ordered by title ascending. You can then call WOOF_Collection::group_by passing in “” to indicate the field “city” in field set “address”, to group by that field.

group_by returns an associative array with:
* keys of unique string values corresponding to the unique cities.
* values being collections of posts with that city value.

So you’re outer loop then displays the cities, and has an inner loop which loops over the stores for that city.

This is more concise, but certainly less obvious than your approach (which is perfectly valid too!).

Latest From the Blog

MasterPress 1.3.10 is now available

9th November 2023

MasterPress 1.3.10 is a feature and bugfix release. Workaround for fatal error introduced by changes to WordPress’ wpdb class in WordPress 6.4. Added actions to MPC files upload_field & WF image save_image functions.

Plugin Requirements

MasterPress requires a minimum of WordPress version 4.9, MySQL 5.6, and PHP version 5.6.20.

We also recommend that PHP is configured to use a memory limit of 64MB per request (128MB may be required for sites with higher complexity).

This plug-in is not compatible with the hosted service.

Three AM