Skip Navigation

[Resolved] Views filter set by taxonomy of the page where it is displayed not working

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is the user's Views filter set by taxonomy of the page is not working.

Solution:

In this case the user had some custom code that is causing the query to not work. If there are any custom code on your site relating to taxonomy please remove it temporarily and try again.

This support ticket is created 6 years, 11 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 19 replies, has 2 voices.

Last updated by Johan Marneweck 6 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#613755

I am trying to: show the body of a custom post type called: top-ad on a single view of a post type called supplier.
Both share the same taxonomy: supplier-category
I want to filter it so that only ads display that are linked to any of the same categories as the supplier on which this banner is being displayed.

Link to a page where the issue can be seen: hidden link

I expected to see: The banner, as in: hidden link

Instead, I got: the body content of a random supplier(not the body content of the top-ad)

This is extremely weird for me, and makes now sense.

#613757
error.png

here is a screenshot of what is not supposed to be displayed (the text under the menu)

#613811

Shane
Supporter

Languages: English (English )

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

Hi Johan,

Thank you for contacting our support forum.

So to get a clear understanding of this. You want to filter a view by the taxonomy of the current page being displayed and you also want the text below the menu to not show.

Could you let me know which view this is that you are having issues with ?

Thanks,
Shane

#614083

Hi,

So to get a clear understanding of this. You want to filter a view by the taxonomy of the current page being displayed - YES

The text showing, is from some random suppliers, when the view that is inserted there is actually for top-ads. You see it shouldn't be displaying anything from suppliers there since it is not a view for suppliers. It is supposed to be showing the content from top-ads, which basically contains a shortcode that generates a banner. (like in the example page I sent you. It works here because there is no filter on taxonomy. The moment I add that it breaks the whole view.)

#614084

The view in question here is Top Ads - per category - 91280

#614320

Shane
Supporter

Languages: English (English )

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

Hi Johan,

I see the major issue here. There might be something wrong with the view itself and as such I would recommend that you remove this view and then recreate it and let m e know if the issue still remains.

It could also be from a plugin conflict so if the recreating of the view does not work I would suggest temporarily disabling all your non-toolset plugins and then try again.

Please let me know if this helps.
Thanks,
Shane

#617665

Hi, I tried recreating the view and also I disabled all plugins except the Toolset ones and still the problem persists.

#617917

Shane
Supporter

Languages: English (English )

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

Hi Johan,

Would you mind if I took a duplicator package from the website so that I can perform further testing ?

Thanks,
Shane

#617923

No I do not mind

#618469

Shane
Supporter

Languages: English (English )

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

HI Johan,

Just an update on this, i was able to create the duplicator package but i'm still trying to figure the issue at hand.

Thanks for the patience.

#618775

Hi

Any feedback on this?

I need to get this working ASAP or at lest a workaround to get it working for nw would be fine. Some PHP script for a shortcode could even be a solution.

Please advise.

#618783

Shane
Supporter

Languages: English (English )

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

Hi Johan,

I'm still working on this one for you but the forum has been quite busy lately.

I must apologize for the delay.

Thanks,
Shane

#618805

Shane
Supporter

Languages: English (English )

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

Hi Johan,

I was able to find the issue.

This was the code that was causing the issue.

add_action( 'pre_get_posts', 'exclude_cpt' );
function exclude_cpt( $query ) {
    if ( $query->is_tax('supplier-category') ) {
        $query->set( 'post_type', array('supplier') );
    }
    return $query;
}

Its overriding our views query and setting them to only return posts from the Supplier CPT.

When I commented out the code the views work normally.

Thanks,
Shane

#618809

Ah I see. I added that code initially to remove another custom post type that was displaying amongst my suppliers because it was using the same taxonomy.

I will test it properly and let you know if all is well.

#618820

OK so now I need help in removing the other posts using the same taxonomy from my suppliers and decorlogue category archive pages. For example: hidden link

"American Shutters Top Ad" is a new post type I created called Top Ad. I use it as a container for the top banners on these supplier and decorlogue pages and category pages. They share the same taxonomy so that I can show ads specific to a certain category on the supplier category pages. How do I change this so that the ads don't show up on these category pages?