Jump to content
Arctic

Looping through multiple page reference fields

Recommended Posts

Hello!  I suspect I'm overlooking something simple, but I'm trying to loop through several page reference fields at once. However, this only returns results from related_1.

	$tags = $page->getFields('name=related_1|related_2|related_3');

	foreach($tags as $tag) {
		echo "<a href='$tag->url'>$tag->title</a>";
	}

 

Share this post


Link to post
Share on other sites
$pagefields = $page->getFields();

if(wireInstanceOf($pagefields, FieldtypePage)) {
	foreach($pagefields as $pf) {
		echo "<a href='$pf->url'>$pf->title</a>";
	}
}

Not tested, it might work though.

Share this post


Link to post
Share on other sites

Thanks, that helped! Here's what worked in the end.

$allFields = $page->getFields();
	foreach ($allFields as $related){
		if (strpos($related, 'related') === 0) { //get just the fields that start with related
			foreach ($related as $tag){
		   		echo "<a href='$tag->url'>$tag->title</a>";
			}
		}
	
	}

 

  • Like 2

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...