Jump to content

Search for template's field


nexuspolaris
 Share

Recommended Posts

Hello!

I am developing a website with search form based on skyscraper profile. I want to filter in the search form for companies by region. I made a "company" template with "region" field. Now I can search for companies by title but I need help in searching for region field.

This is my search-formp.php file:

<?php 
$companies = $pages->find("template=company");
$regios = $companies->region;
?>

<form method='get' action='<?php echo $config->urls->root?>search/'>
  <select id='company' name='company'>
          <option value=''>Any</option>
            <?php foreach($companies as $company) {
                  $selected = $company->name == $input->whitelist->company ? " selected='selected' " : '';
            }
           ?>
  </select>
  <select id='regio' name='regio'>
          <option value=''>Any</option>
            <?php foreach($regios as $regio) {
                  $selected = $regio->name == $input->whitelist->regio ? " selected='selected' " : '';
            }
           ?>
  </select>
</form>

 

Link to comment
Share on other sites

I assume, you want the $regios to be an array of all available regions.

Let me start with how I would solve this:

  • Create two templates, 'regions' and 'region'. Configure the family settings to:
    • 'regions' only 1 allowed and only template 'region' as children allowed
    • 'region' many allowed, no children allowed, parent only 'regions' allowed
  • Use a page reference field with text tags option, limited to the template 'region' and parent 'regions'.
    • You can enable the 'create pages from field' option to instantly create new 'region' pages when not yet available

This method is the easiest from a frontend point of view, because your query boils down to:

$regios = $pages->find('template=region,sort=title');

For your case, it is more complicated because you cannot just query all the unique region names with your solution.

You need to get into directly querying the database. I found this (a few years old, but still accurate I think):

 

 

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