Skip Navigation

[Gelöst] Help with creating a view.

This support ticket is created vor 4 Jahren, 8 Monaten. There's a good chance that you are reading advice that it now obsolete.

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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Artikel
#1554033

On my website https: // versteckter Link I use a view on taxonomy to show filtered entries on a map.

With the help of further filters below the map, my visitors should be able to further filter the display of the contributions on the map using check boxes.

My problem:
If I want to do this using the Taxonomy filter, all taxonomies are always shown below the map. How can I limit these to the taxonomies I want?

Kind regards

#1554185

Hello, if I understand correctly you would like to allow your site visitors to filter a View by taxonomy term(s) using checkboxes. However, you do not want to filter by all the terms in this taxonomy. You would like to filter by some specific terms. Is that correct? If so, there is not an easy way to do this in wp-admin but there is a solution that requires custom code. A colleague Nigel proposed the solution in another forum ticket: https://toolset.com/forums/topic/post-form-categories-how-to-only-display-select-categories/

In order to implement this solution, we can customize that code snippet a bit to work for your site.

1. Please tell me more about where this View is displayed on the site. Is the View displayed on every post in a custom post type? Is it displayed in a custom Page, or several custom Pages? Is it in only one Post? Is it included in a WordPress Archive or several Archives?

2. Which taxonomy are you filtering on - Categories, Tags, or a custom taxonomy? Please provide the taxonomy slug.

3. Which terms would you like to include, or exclude? Please provide those term slugs. For example you can:
- include all terms except "nicht-kategorisiert" in the default Categories taxonomy
OR
- include only "schwarz", "weiß", "braun", and "blau" in the Farben taxonomy

#1554447

Hi there,
Yes that is correct. I want visitors to my website to be able to filter my view based on a certain selection. The choice would be certain WordPress categories.

Re 1. The view is shown in the form of a map on one of my WordPress pages versteckter Link. WordPress posts with certain categories are to be displayed normally.

To 2. I filter articles from the main category park-und-uebernachten

3. I would like the following sub-categories to be filtered by visitors to the website using Chekboxes:
campsites
parking spaces
picnic areas
parking spaces
winter camping

This means that after ticking the checkbox, only the contributions of the selected subcategory are shown on the map above the form.

Kind regards

#1555013

Okay here is an updated script for you:

function tssupp_restrict_terms( $terms, $taxonomies, $args, $term_query ){

    // 1. pages where form (or search View) is inserted
    $pages = array( 12345 );

    // 2. which taxonomy (slug)
    $taxonomy = 'park-und-uebernachten';

    // 3. add terms to blacklist *OR* whitelist, not both
    $blacklist = array();
    $whitelist = array( 'campsites','parking-spaces','picnic-areas','winter-camping' );

    if ( is_page( $pages ) && $taxonomies[0] == $taxonomy ) {

        if ( !empty( $blacklist ) ) {

            foreach( $terms as $key => $term ){

                if ( in_array( $term->slug, $blacklist ) ) {
                    unset($terms[$key]);
                }
            }
        } elseif ( !empty( $whitelist ) ) {

            foreach( $terms as $key => $term ){

                if ( !in_array( $term->slug, $whitelist ) ) {
                    unset($terms[$key]);
                }
            }
        }
    }

    return $terms;
}
add_filter( 'get_terms', 'tssupp_restrict_terms', 10, 4 );

You should replace 12345 with the numeric ID of the Page Stellplatz. You can find the numeric ID if you edit the Page in wp-admin. In the URL you will find the page ID in the post URL parameter like this:

https://yoursite.com/wp-admin/post.php?post=12345&action=edit

You can add this custom code in a child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom Code

Let me know if you have questions about that.

#1555161

Hello, thank you.
What needs to be done in the admin of the site? Does the view need to be deleted there?

Kind regards

#1555363

Hello,

I have adapted the code and inserted it into the Functions.php of my child theme - unfortunately without success. All categories are still displayed below the map and the wrong markers on the map. Unfortunately I now also have a white login page?

Kind regards

#1555471

Hello,

the script causes a white login page. The page with the ad (versteckter Link is also white.

Kind regards

#1556517

If you have a WPOD, you should remove this code from your theme. May I log in and take a closer look? Please provide login credentials in the private reply fields here.

#1556661
20200319_203518.jpg

Hi there,

I imagine the page like this.

Kind regards

#1559293

Okay I have a bit more clarity here. You provided this link:
https://www.womo-reisen.de/stellplatze/

That link is not correct. It should be:
https://www.womo-reisen.de/stellplaetze/
That was very confusing for me, sorry!

One more thing is I thought you had created a custom taxonomy with the slug park-und-uebernachten but that is not accurate, instead you added a taxonomy term to one of the default WordPress taxonomies, Kategorien. The term slug is parken-und-uebernachten.

Then the slugs for the whitelisted terms should be:
- campingplaetze
- parkplaetze
- picknicklaetze
- stellpaetze
- wintercamping

That's as far as I got today, I am closing for the day and will follow up with you tomorrow. Thank you for the screenshot, I will take a closer look tomorrow.

#1562733

Okay please check now, I have updated the View and checkboxes.

#1562923

Hello Christian,

Thank you for your help. I notice 3 problems:

1. After the first update (after activating the first checkbox, all checkboxes from all categories are loaded again.

2. If several checkboxes are activated, only the results that meet the criteria of all checkboxes should be displayed. Example:
Activation of the "Germany" checkbox and the "Parking spaces" checkbox should only display parking spaces in Germany. Not both categories.

3. The article images in the entry list under the card are no longer the full size.

I ask for examination.

Thanks a lot!

Kind regards

#1562967

Hello Christian,

I was able to solve problem 2 of my last message by changing the filter myself.

Problems 1 and 3 are still relevant. The article images shrink even after the filter is first updated (checkbox activation)

Kind regards

#1564307
box-class.png
no-ajax.png

1. After the first update (after activating the first checkbox, all checkboxes from all categories are loaded again.
Yes unfortunately one limitation of this approach is that AJAX updates are not supported, and a submit button is required. I have added a Submit button and updated the View so that AJAX is not used (see no-ajax.png).

3. The article images in the entry list under the card are no longer the full size.
Well, I didn't make any changes in the loop template, I only adjusted the filters. The loop template is here:
versteckter Link
I deleted the class "box" because it was restricting the content width to 960px on larger devices (see box-class.png). Can you take a look now?

#1564573
20200319_203518.jpg

Hello Christian,
Thank you very much!! My problems are almost solved.
I still have a problem and a question:

1. The first time you access the "Pitches" page, posts from all categories and posts without a category are displayed. The result should be that on the page "parking spaces" without activated filter only articles of the category "park-und-overnight" are displayed.

2. How can the checkboxes be arranged in several columns under the map?
(see photo)

Kind regards