Jump to content

Looping through multiple page reference fields


Arctic
 Share

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>";
	}

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...