Extension, Module

Archived
Forum
(read-only)

PaternitEE

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4

Back to this add-on's main page
View Other Add-ons From Conflux Group, Inc.

     

Getting results when some filters are populated and some are not

General

elsmore
elsmore

Really happy so far with PaternitEE. I’m just playing around with multiple channels as categories, and I’m trying to get results when only one of two filters are populated. Using GET, I get no results if I only select one option in my form. Here’s the form:

<form method="get" action="{path='vacancies-new/filter'}">
        <
select name="vacancy_sector">
          <
option value="">Any</option>
          
{exp:channel:entries channel="sectors" dynamic="no" disable="category_fields|member_data"}
          
<option value="{url_title}">{title}</option>
          
{/exp:channel:entries}
        
</select>
        <
select name="vacancy_location">
          <
option value="">Any</option>
          
{exp:channel:entries channel="locations" dynamic="no" disable="category_fields|member_data"}
          
<option value="{url_title}">{title}</option>
          
{/exp:channel:entries}
        
</select>
        <
input type="submit" value="Go!">
      </
form

And here’s my PaternitEE tag:

{exp:paternitee:entries channel="vacancies" search:vacancy_internal="=No" use_get="yes"  disable="category_fields|member_data" limit="3"}
    {if no_results}
<p>No results</p>{/if}
...
{/exp:paternitee:entries} 

I do get results if I use both form fields (and there are corresponding entries of course).

If I use results_with_no_filters I get all entries returned, with no filters applied even if I select one.

Any idea where I’m going wrong?

 

Jeremy Gimbel, Conflux Group, Inc.
# 1
Developer
Jeremy Gimbel, Conflux Group, Inc.

Hi,

Thanks for getting in touch!

So I think you may be running into an inherent limitation with PaternitEE at this point. I can certainly look into changing the way it works, but I believe what it’s doing now is searching the second field for a blank value, rather than searching only the one field. I need to think through the ramifications of dropping blank values from the GET search parameters before committing to that change.

That said you have a couple options.

First, you could use some JavaScript to handle your form’s submit event, process the selections and generate a URL to redirect to for results based on the selections. This would be fairly simple and would allow you to drop the fields out that have no value.

Another option would be to use Rob Sanchez’ Mo’ Variables, which would give you access to the GET variables from the results template, and then feed them to the PaternitEE tag conditionally. Something like this (untested but should work):

{exp:paternitee:entries channel="vacancies" search:vacancy_internal="=No" use_get="no"  disable="category_fields|member_data" limit="3" {if get:vacancy_location != ''}field:vacancy_location="{get:vacancy_location}"{/if} {if get:vacancy_sector != ''}field:vacancy_sector="{get:vacancy_sector}"{/if}
    {if no_results}
<p>No results</p>{/if}
...
{/exp:paternitee:entries} 

Since the Mo’ Variables {get:xxx} variables are parsed early, this or something similar should work.

 

elsmore
# 2
elsmore

Thank you for the quick reply and the suggestions - Mo’ variables works like a charm!