Jump to content

Testing for Page / Category membership


FrancisChung
 Share

Recommended Posts

Hi there,

This is a follow up question from my Page/Category question.

https://processwire.com/talk/topic/10738-categories-not-visible-incorrect-setup/

I have a reference to the Category page I want to test membership for :

$catgoryPage = $pages->find("parent.id=[path=/categories/, include=unpublished], title=$category");

I want to test if a particular page's field, Category (type:Page Fieldtype) == $categoryPage.

I've been trying for the last hour on how to test membership for this page object without any success.

I have tried 

1) using the find method but I'm not sure how I can describe a field category == $categoryPage

2) looping through a PageArray, get the fields Array and using the has method on it.

$testPages->fields->get("category")->has($categoryPage)

3) I have tried to search the forums but have found none related to my issue.

Am I approaching this problem incorrectly or is there a simple answer to this?

Thanks in advance

Link to comment
Share on other sites

You're page field is preset with fixed pages to choose from, so I'm not sure what exactly you want to compare here, but to do compare a page (from the field) with a page(from the selector) just use this:

$pageSelector = $pages->find("…");
$pageField = $page->myPageField;

if($pageSelector->id == $pageField->id){
  // We have a match
}
  • 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
 Share

×
×
  • Create New...