• Hi! So I noticed inconsistent results with a custom tax query where some taxonomies were filtering as expected, and others were being completely ignored.

    I did all the debugging myself, and came to the below conclusion.

    In the function relevanssi_get_term_in() (in lib/search-tax-query.php), the following line:

    $term = get_term_by( 'name', $name, $taxonomy );

    expects $name to be a ‘name’, never giving it the option of being a ‘slug’, despite comments suggesting it does. Then, when I changed my arguments to use ‘name’ instead of ‘slug’, it still didn’t work, because when relevanssi_term_tax_id_from_row() runs its query, it grabs its type from $row['field'], which was of course now set to ‘name’. The problem here is that it looks at this type (‘name’) against the terms created on this line of relevanssi_get_term_in() (line 360):

    $name = sanitize_title( $name );

    So it’s creating slugs from names and searching the database for terms whose names are these slugs. To be fair, WordPress is really inconsistent with its naming! (With its slugging?)

    The funny thing is that this, of course, works just fine if the term only has one word.

    And that explained my inconsistency, and why it seems to have worked when it was introduced in 3.5.9. My taxonomy term of “Healthcare” worked great. “Life Sciences” did not. You can imagine how much of a headscratcher that was until I dug in!

    So to replicate this: Create a taxonomy term with two or more words so that the slug does not match the name. Then do a custom tax_query by ‘slug’. (Or even by ‘name’.)

    Once I found the issue, I discovered it worked to use ‘slug’ but pass in names. But I didn’t like doing that, so I instead worked around it by using IDs. That’s working well, so I don’t need an immediate fix. But I think it would be great to get that truly working!

    Let me know if you’re able to replicate or if you need more info from me.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Rebekah Blackmon

    (@rblackmon7)

    I also just realized my topic name is ambiguous! It’s supposed to read: “Custom Tax Query by name/slug only appears to work [but doesn’t actually]”. ??

    Plugin Author Mikko Saari

    (@msaari)

    This is a known bug in the current version (which my tests didn’t catch, because I used ambiguous taxonomy names – once I changed my tests so that the taxonomy term name and slug were different, I caught it). Does the problem go away if you replace /lib/search-tax-query.php in Relevanssi with this file from GitHub?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Tax Query by name/slug only appears to work’ is closed to new replies.