cb2004 Posted August 27, 2018 Share Posted August 27, 2018 I am building a membership site and the member can have a number of stores assigned to them. The data for the stores is underneath a sub page of home with template store-detail. The stores are then assigned to the user template with a page reference field. The stores will be visible in the frontend, and i want them to be paginated, what would the find be to search for the stores if the user is published. I think I am falling down because the reference is in the user template and not the stores. Thanks all. Link to comment Share on other sites More sharing options...
OLSA Posted August 27, 2018 Share Posted August 27, 2018 Hello, if page reference field is on user template, then you can try this: $stores = new PageArray(); $users = $pages->find('template=user'); foreach($users as $user){ $stores->add($user->stores); // "stores" is page reference field name on user page } // now $stores contain desired stores pages, check with var_dump or foreach()... // pagination $pagination = $stores->renderPager(); There is option to go with direct sql query, but I'm not sure how that would be "clean" (readable) plus for that need to do some preparation (also using queries). I'm still with PW 3.0.98, but if you are using some of latest dev. versions (>3.0.98) try to find text about new functionality that has been added to page reference field. Maybe that can helps to find some another approach. Regards. Link to comment Share on other sites More sharing options...
bernhard Posted August 27, 2018 Share Posted August 27, 2018 two things: 1) i think this would be a perfect fit for or That way you can either add a store to the user or add a user to the store. How do you make sure that every store has only one assigned user? Or is this not necessary? You might need to take care of that as well. 2) To anwer your question ? I think the easiest and maybe best option would be to add a checkbox field (eg "user_published") to the store template and set the value of the checkbox via a saveReady hook. You could then just do a $pages->find('template=store,user_published=1'); and use all the internal pagination features. 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