Skip Navigation

[Résolu] Parametric Search is not refreshing the results.

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: Have a View that queries a custom post type and then adds a parametric search with a filter for that custom post type.

Solution: You can't run 2 post queries on the same custom post type, the solution is to alter the data structure so that the custom post type can first be queried and then filtered using a taxonomy.

Relevant Documentation: N/A

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 4 réponses, has 2 voix.

Last updated by marcusC-4 Il y a 5 années et 6 mois.

Assigned support staff: Nigel.

Auteur
Publications
#401096

I have a parametric search setup to filter the table at the bottom of this page: hidden link

When the page initially loads, the table & the Neighborhood selection options look correct. However, once you select a neighborhood, the table does not get filtered and all neighborhoods are now visible in the selection field instead of just the ones relevant to the page. Do you see anything in the below code that could be causing the issue?

Here is the code for the filter

<div class="idoc-properties-search filter-list row">
[wpv-filter-start hide="false"]
[wpv-filter-controls]
  <div class="one-fourth">
    <div class="search-header">
    <h3>Pricing and Options</h3>
    <p>Use Filters</p>
  </div>
  </div>
  <div class="sbox one-fourth">
    <label>Neighborhood</label><br />
 [wpv-control-set url_param="wpv-pr-child-of" ancestors="neighborhood-name"]
	[wpv-control-item type="select" ancestor_type="neighborhood-name" default_label=""]
[/wpv-control-set]
  </div>
  <div class="sbox one-fourth">
    [wpv-control field="has-basement" url_param="has-basement" type="checkbox" title="Basement"]<br />
    [wpv-control field="finished-basement" url_param="finished-basement" type="checkbox" title="Finished"]
  </div>
[/wpv-filter-controls]
[wpv-filter-end]
</div>

And here is the code for the loop output in that View:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<table width="100%" class="model-list">
		<thead>
			<tr>
				<th>[wpv-heading name="post-title" id="$neighborhood-name"]Neighborhood[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-finished-square-feet"]Finished Sq Ft[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-total-square-feet"]Total Sq Ft[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-has-garage"]Garage[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-spaces"]Spaces[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-has-basement"]Basement[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-finished-basement"]Finished[/wpv-heading]</th>
				<th>[wpv-heading name="types-field-price"]Price[/wpv-heading]</th>
			</tr>
		</thead>
		<tbody class="wpv-loop js-wpv-loop">
		<wpv-loop>
			<tr>
				[wpv-post-body view_template="Loop item in Model Search"]
			</tr>
		</wpv-loop>
		</tbody>
	</table>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

I have a Query Filter setup by post relationship to Select posts that are children of...Post where this View is shown.

Thanks

#401133

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+00:00)

The link for your site is password protected so I couldn't see the problem in action.

I set up a bare bones test site to see if I could narrow down the problem.

I created a post type Neighborhoods, and a child post type called Units, and then created some sample Neighborhoods (Brooklyn, Manhattan, Queens) and added some sample Units to them (e.g. apartments, brownstones, attics).

I then created a parametric search View to display Units that can be filtered on the front-end by Neighborhood, the results updating via ajax when a different neighborhood is selected.

I then added my view via shortcode to a page, where I initially saw all of my units listed, and which I could then filter by selecting a neighborhood.

Observations:

All I displayed in my view was the unit post title as a link. Your loop output is rather more complex, but that doesn't affect what is actually returned by the loop. You could check for errors by testing swapping out your loop output to just show the post title.

When I strip out the HTML you have added to your filter controls it is essentially identical to mine:

[wpv-filter-start hide="false"]
  [wpv-filter-controls]

    [wpv-control-set url_param="wpv-pr-child-of" ancestors="neighborhood"]
      [wpv-control-item type="select" ancestor_type="neighborhood" default_label=""]
    [/wpv-control-set]

  [/wpv-filter-controls]
[wpv-filter-end]

Which leaves your final line, "I have a Query Filter setup by post relationship to Select posts that are children of...Post where this View is shown."

I'm not sure what you are doing here, where you are displaying your view.

For testing, remove that query filter, and add your view to a page and view that page. Does your parametric search work?

Can you explain where you are adding your View and what you intend to achieve with the query filter you added?

#401273

Hi Nigel,

Thank you trying to replicate the issue & sorry for not giving you the password to view the site. It is MonicaB

I tried removing the Query Filter & adding the view to a blank page, but that didn’t fix the issue with the Neighborhood selection not working.

On this parametric search, I have an option to select the neighborhood or use checkboxes to choose homes with a Basement or a Finished Basement. The checkbox filters are working correctly, so it is definitely an issue with the Neighborhood selector. I’ll explain the relationships:

This is a real estate site & the page you are viewing is a CPT called "New Construction Home". This home has not yet been built so there are several variations, which we have setup as children and we are calling those Models.

The Models are also children of Neighborhoods. Each Model can only exist in one Neighborhood so that relationship works well.

The view that is controlling the table is setup to display Models & then uses the code & criteria that I listed above. The reason we are using the Query Filter is to link the Models in the table to the New Construction Home that you are viewing, depending on which page you’re on. When the page initially loads, it is working correctly & only shows Models for that specific New Construction Home. The only part that doesn’t seem to be working correctly in the table or in the parametric search is the Neighborhood selector.

I have double-checked that all Models are linked to Neighborhoods & that I have the slug spelled correctly in the View code. I’m sure it’s something small that I’m missing, but I can’t seem to get this to work.

#401452

Nigel
Supporter

Languages: Anglais (English ) Espagnol (Español )

Timezone: Europe/London (GMT+00:00)

First, the bad news. That isn't possible the way you have set it up. You are performing a post query on your models (based upon New Construction Home) and then performing another post query on your models (based upon Neighborhood). One of them will trump the other (and in this case your content query will trump your parametric search query).

Now, the good news. You can make this work by making your parametric search filter a taxonomy query, and your Neighborhood CPT seems like a perfect candidate to be changed to be a custom taxonomy.

I ran some quick tests and got it working how you describe but using a taxonomy for neighborhoods without problem.

#401786

Thank you, Nigel. That cleared it up.