Skip Navigation

[Gelöst] I want to show on one page, two Views that use the same URL parameter for a custom field Query Filter

This support ticket is created vor 3 Jahre. There's a good chance that you are reading advice that it now obsolete.

Dies ist das technische Support-Forum für Toolset – eine Suite von Plugins zur Entwicklung von WordPress-Websites ohne PHP-Pogrammierung.

Jeder kann in diesem Forum lesen, aber nur Toolset-Kunden können darin Beiträge veröffentlichen. Der Toolset-Support arbeitet 6 Tage pro Woche, 19 Stunden pro Tag.

This topic contains 9 Antworten, has 3 Stimmen.

Last updated by Shane vor 2 Jahre, 12 Monate.

Assigned support staff: Shane.

Author
Artikel
#1347519

I choose a city in the filter options and then only the appartement results in this city are shown.
I also have houses and not only appartements. Theses houses are another post type. I want that the houses in the already choosed city will be showed underneath the result with the appartments .

Also when I am on a detailed page from one of the appartement results that all the rest of the appartements that are in the same city or the same size (square meters) are shown as related results.
I found already an articel about related results but that doesn't work like I want. Because there is not really a relation between theses results or post types. They only both have a field for city.
I hope you know what I mean.

#1347545
url.png
shortcode.png

I want that the houses in the already choosed city will be showed underneath the result with the appartments .
Okay sure, you can create another View of Houses instead of Appartments. Then add a Query Filter for the city custom field, and configure it to respond to a URL parameter (see url.png). The URL parameter must be identical to the one in the Appartments View. Build the Loop of the View to display Houses, and then insert this View in the page where the Appartments results are shown.

Also when I am on a detailed page from one of the appartement results that all the rest of the appartements that are in the same city or the same size (square meters) are shown as related results.
Normally the best way to do this is to configure Query Filters to respond to shortcode attributes. So in a View of Appartements you would add a City field Query Filter, set to respond to a shortcode attribute like cityids (see shortcode.png). Then when you insert this View into the Appartements template, you will add the shortcode attribute cityids, and use the Types Field shortcode to set the value from the current Appartements post. Something like this:

[wpv-view name="appartements-in-same-city-view" cityids="[types field='city' output='raw' item='$current_page'][/types]"]

You can see that the "city" custom field value is used to set the filter criteria for the appartements in the same city View. This technique is called passing arguments into Views, and can give you powerful, dynamic filtering capabilities.

Check out this article on passing arguments into Views for more information: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#1354209

Where can I add this shortcode in Elementor?
[wpv-view name="appartements-in-same-city-view" cityids="[types field='city' output='raw' item='$current_page'][/types]"]

#1355373

Shane
Supporter

Languages: Englisch (English )

Timezone: America/Jamaica (GMT-05:00)

1347545-shortcode_1.png

Hello,

Thank you for contacting our support forum.

It seems Christian provided how to do this with a shortcode parameter, however what you want is a URL parameter to filter the second view.

If you take a look at the screenshot that Christian provided here, you will see that it is set to a shortcode parameter.

What you need to do is to add the query filter to your second view and then set it to get the value from the URL parameter and then write what your url Parameter is.

This should allow your view to be filtered by a url parameter.

Thanks,
Shane

#1356775

Now I understand nothing anymore!
Is it possible to set up a video chat with a WPML expert? I would also need a support for another bigger problem.

Best regards,
Christina

#1357233

Shane
Supporter

Languages: Englisch (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christina,

Just to clarify, you want to filter your view by a URL parameter correct ?

Meaning you want to place the view on a page, then navigate to that page and add a parameter in the URL ?

Example hidden link

Please let me know.

Thanks,
Shane

#1357605

I would say yes. Because I have a view with search, filter and results. Than I also have an extra second result view on the same page and this view should be filtered like the other view. so I think the solution is via url parameter.

#1358289

Shane
Supporter

Languages: Englisch (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Then the solution here would resolve the issue for you.
https://toolset.com/de/forums/topic/i-want-to-show-on-one-page-two-views-that-use-the-same-url-parameter-for-a-custom-field-query-filter/#post-1355373

All you have to do is add a query filter to your second view for your custom field as depicted in the ticket above, then set it to the URL parameter that you want it to get the value from, then your view should get filtered by that url parameter once it appears in the URL.

If there is anything that is not clear please let me know.

Thanks,
Shane

#1359171

Ok thanks. That only works when the two views are on the same page. Or am I wrong?
I have a page with a search and results and then I click on one of the results and the detail page will open. On the detail page of the result the urlparameters from the search are not there anymore. But on this page I also have related posts to this post (the detailed page of one of the results).

I also want to show the image from a custom field. I created in the acf an image and used "image url" as an return format but it still always shows the ID of the image.

#1359237

Shane
Supporter

Languages: Englisch (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

IT will work even if its the only view, because as long as there is a url parameter in the URL then the view will filter.

"On the detail page of the result the urlparameters from the search are not there anymore."

This is to be expected because you've navigated away from the page that had the url parameter. In order to get that parameter into the URL you will need to construct the URL to that page manually by doing something like this.


<a href="[wpv-post-url]/?myparam=[wpv-search-term param='urlparam']">[wpv-post-title]</a>

This will transfer the param to your link to the details page of the post to filter the view as well. Now you need to replace myparam and urlparam with the parameter that the view is expecting from the URL.

Please let me know if this helps.
Thanks,
Shane

Das Forum „Toolset Professioneller Support“ ist für neue Themen und Antworten geschlossen.