Jump to content

Find Related Pages


MikeS
 Share

Recommended Posts

New to ProcessWire and seriously loving it.  I'm also relatively new to PHP (there is my disclaimer!).  I am trying to come up with the following PHP statement to find related pages.  I would like to find all pages where "some_field" contains the page title of the current page.  So the statement might look something like this:

<?php $matches = $pages->find("some_field *= title of the current page"); ?>

Greatly appreciate any nudge in the right direction. Thanks.

  • Like 1
Link to comment
Share on other sites

Welcome to PW!!

You pretty much had it :)

$matches = $pages->find("somefield*={$page->title}");

$page is always the current page. You can't have spaces within each part of the selector, so I remove the spaces around: *=

Remember that if you are "find"ing you will end up with an array of results, not just one, so you need to decide how to handle these. The usual approach is to foreach through them. So you would then:

foreach($matches at $match){
    echo "<li>{$match->title}</li>";
}

or something along those lines.

  • Like 5
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...