Forum

Thread tagged as: Question, Addons

Filter region by user

I'm creating a website that allows users in perch to create recipes. I am also using the blog app to allow the same users to create articles, thus I have a page for authors that displays posts from the author. I also want to filter my recipe region by the same user account that the recipe was created by.

How would I go about doing this?

Mike Barker

Mike Barker 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd need to add a field to the region to hold details of the user, and then filter by it.

Are you suggesting something like a text input that the user fills the slug in? Ideally the post would be shown a select box of author to publish as. As that possible?

Drew McLellan

Drew McLellan 2638 points
Perch Support

How you implement it is up to you, but you'd need the data to be able to filter on it.

Could you possibly help me in the implementation? I've taken a look under the hood within perch and have found this:

$opts = array(); foreach($authors as $author) { $opts[] = array('label'=>$author->authorGivenName().' '.$author->authorFamilyName(), 'value'=>$author->id());
} echo $Form->select_field('authorID', 'Author', $opts, isset($details['authorID'])?$details['authorID']:$Author->id());

Is there a way to replicate this functionality within a perch template?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you added a field to your template to indicate the author?

No, I'm fine with the filtering part I just don't know how to make the select box dynamic based on the users in Perch. Is this possible?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, so you'd need to create a field type for that.

https://docs.grabaperch.com/api/field-types/

I thought so. Thanks for you help.