Jump to content

Find pages with a field matching $page->parent->title


Recommended Posts

Posted

Stumped with this....please can anyone help?

I'm trying to find pages with a field that matches the search page's parent's title.

This works 

$items = $pages->find('template=items-ordered,supplier=Acme Biscuits');

Not this...(did no find any pages).

$items = $pages->find('template=items-ordered,supplier=$page->parent->title');

With thanks ? 

Posted

You could try

$parent_title = $page->parent->title;
$items = $pages->find('template=items-ordered,supplier=$parent_title');

 

 

Posted

You need double quotes. If you had debug on, this would have thrown an exception:

1 hour ago, dab said:

$items = $pages->find('template=items-ordered,supplier=$page->parent->title');

Change it to this:

$items = $pages->find("template=items-ordered,supplier={$page->parent->title}");

 

  • Like 1
Posted

Many thanks! Both worked. I had tried with {....} but obviously also needed the double quotes. I was outputting directly to .csv which was clearly not the best way to debug! Thanks again.

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...