Support » Fixing WordPress » Show posts that are in both categories via cat1+cat2 in url doesn’t work

  • It seems like i am the only person on this planet currently experiencing this issue. When i search for (as an example), it should only show posts, that are in BOTH categories, but it only acknowledges the first category tag.

    A Developer said: Confirmed. SQL contains a 0=1 clause when category name contains a ‘+’. I thought a workaround would be to use “pre_get_posts” action to intercept “category_name” query vars containing a ‘+’ and compose a “tax_query” arg instead using ‘operator => ‘AND’, . Same result, the SQL ends up with a 0=1 clause.

    I have submitted this issue now to Fixing WordPress and Core but no one seems to care. So i am asking: has anybody an Idea how to fix this issue? I’ve build on this mechanism for years now and no, i don’t want to purchase another plugin and fix thousands of links containing this structure.

    For Reference, my Tickets: |

    I have received the following info, but since i just started using WordPress a couple months ago (moved from Blogger) and never ever tried working with PHP and such (i know basic HTML and CSS), i was asking if someone has an idea how to make this work?:

    The docs offer several ways of doing a category intersection.

    $query = new WP_Query( array( ‘category__and’ => array( 2, 6 ) )); One of the methods mentioned on that page (unsure 100% whether it does an intersection because I haven’t tested it) is a slug+slug format, which loosely implies it does an intersection, but in any case it looks familiar to your use case.

    Here is my functions.php:–B7hppQGtVAhUKcVEAEkimr/view?usp=sharing And here are the Snippets i use in functions.php through the Code Snippets Plugin:

    As far as i know this has been an issue since 5.8.?. Im currently running 6.0.1. I’ve tried reinstalling WordPress and Safe Mode; nothing changed.

    List of Plugins:
    301 Redirects Pro
    Advanced Ads – PopUp and Layer Ads
    Advanced Ads Pro
    Advanced Ads – Sticky Ads
    Advanced Ads – Tracking
    Advanced Ads
    Amazon Product In a Post
    Awesome Support
    Better Search Replace
    Code Snippets
    Delete Me
    Easy Theme and Plugin Upgrades
    Forminator Pro
    GDPR Data Request Form
    LiteSpeed Cache
    MihanPanel Pro
    MyThemeShop Theme & Plugin Updater
    Real Cookie Banner
    Schema & Structured Data for WP & AMP
    Stop E-Mail for
    Stop WP Emails Going to Spam
    Advanced Editor Tools (previously TinyMCE Advanced)
    TotalPoll – Lite
    Two Factor
    User Menus
    White Label CMS
    WP Review Pro
    SEOPress PRO
    WP Statistics

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz


    Hi gooloo,

    I’m sorry you’re still having trouble with this. Unless someone can reproduce your problem, it’s impossible to propose a solution. I initially thought I could reproduce the problem, but it turned out I had mis-typed one of the category term slugs in my URL. So anything I said related to what the issue might be has no significance. In any case, I got a failed query due to the 0=1. In your case, the query is working, but not the way you expected.

    Your problem is almost certainly due to theme or plugin influence. Have you tried using the Health Check and Troubleshooting plugin’s troubleshooting mode? This deactivates all plugins and switches to a default theme for your view only. Other visitors will still see your normal site with your theme and all plugins active. In troubleshooting mode, multiple category requests should work as expected.

    With your example URL, are you sure that you’re getting products listed that are not in the vegan category? Do not rely on page titles, they normally only list the first category even though multiple categories are specified. The products listed should have both categories assigned despite the Balea page title.

    Thread Starter Nico


    Hi, so i’ve installed and run that Plugin. Even with Twenty-Twenty Two and no active Plugins this issue persists.
    Yes, i am sure, that non-vegan products are shown (The Balea Lippenbalsam Intensiv contains Beewax and is not categorized as vegan, stills shows up in the results).

    Moderator bcworkz


    Would vegan be a child category by any chance? Child categories are considered to be in the parent or ancestor categories, even when not explicitly assigned. This can lead to unexpected query results.

    While it’s difficult to determine the cause if it’s not reproducible on other sites, there’s a possibility of overriding what ever had gone wrong by directly composing the proper SQL query and imposing that on the process in favor of whatever WP had come up with. Composing a query from any random term1+term2 request gets rather involved, but it’s possible.

    You can override the WP SQL through the “posts_request” filter. Whatever SQL a callback returns will be used to fulfill the request.

    Thread Starter Nico


    Hi, all Categories are child categories. As i moved in 2019 from Blogger with already over 2.500 Posts and ~600 categories, they all just been made into parent categories. Also i can’t create 10.000+ manually added SQL Queries. For each brand (more than 800) there would have to be added more than 20 +markers. Vegan, parabenfree, siliconefree, etc.
    And as WordPress genuinely for more than two years output them just like that, i simply want to go back to that.
    I also have simply no idea about SQL nor PHP. I’ve worked nearly ten years with Blogger and moved to WordPress for simplicity in adding functions (like simple feedback forms). I do absolutely not know how to add any filter. PHP to me is literally gibberish. I have no clue how it works and i can’t wrap my head around it.

    Moderator bcworkz


    Child categories are all implicitly part of the common ancestor, but it’d only be a factor here if balea or vegan were themselves parents of other child categories. Then any products having only those child categories would still be included in category requests for their parents. Requesting a child should not yield products only assigned their parent categories. The implicit relationship should only work downwards, not upwards.

    Assuming the parent/child thing is not the issue here, there’s something very odd about your particular installation, as evidenced by no one else being able to reproduce the same problem. While it is fixable, doing so requires a level of access to your site that is beyond the scope allowed in these public forums. You’d likely need to hire a developer to hook into that filter and patch up the SQL so that it works the way you need it to. Or better yet, determine the root cause and correct it.

    If you don’t already know of a developer, a couple possible resources are or There are also local meetups in many urban centers where WP developers get together IRL. If any are near you, you can likely find help there.

    Please do not attempt to solicit paid help through these forums, doing so is against our guidelines and is unsafe. Go through proper channels intended for the purpose. I recommend you ignore any unsolicited contacts that may arise as a result of this topic. People that do that likely don’t have your best interests at heart 🙁

    Thread Starter Nico


    But how am i supposed to pay for a developer? i have nearly no income through the site and i’ve been doing it for 11 years simply because no one else took the time to actually go full-in to the details of formulas and cosmetics.
    Also, the two links you provided both have no purpose. The first one is people looking for hiring developers, not for actually finding someone; the second one is nothing but the website to the jetpack plugin, which i don’t use or need.
    Also i think that this should actually be contributed to WordPress. Maybe at some point this becomes a regular problem. I think i’m not the only one with 3000+ posts and 1000+ categories; so it is likely that this at some point will happen again.
    Also i am not able to fundamentally learn and fix something i have no clue off. i’d love to read about SQL (and i did; for weeks now) and i don’t understand a thing.

    So at this point i’m actually happy to create a database backup and give ANYONE access to my site who truly thinks they could solve this. I switched to WordPress because i wanted to do things better but since the first day i only struggled with it. Although 2/3 of the web relies on WordPress i truly believe it has never been created to have a couple of hundred posts. It only makes problems and anyone just wants to make money.

    The GPL License too: it’s supposed to be a free web and literally ANYTHING costs money. I have not seen a single person who actually wanted to contribute something apart from the core-team.

    At this point i’m just restless. I am at a point where everything just makes no fun anymore. I can’t use my own website how i want to because a SINGLE FUNCTION apparently ruins everything.

    Thread Starter Nico


    Sorry but i just feel helpless and sad. All i want to do is making it easy for people to filter out by a simple link and after 2 years of perfectly working it simply doesn’t, without me doing anything. And that just makes me crazy. No alteration helps. I tried hundreds of different link formats and no one takes more than the first category put in the link

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Show posts that are in both categories via cat1+cat2 in url doesn’t work’ is closed to new replies.