Here’s the complete error for context. This also happens on each line expecting access to $row['field']
Notice: Undefined index: field in /var/www/html/wp-content/plugins/relevanssi/lib/search.php on line 92
Call Stack
# Time Memory Function Location
1 0.0013 366632 {main}( ) .../index.php:0
2 0.0019 366920 require( '/var/www/html/wp-blog-header.php' ) .../index.php:17
3 0.3736 4512504 wp( ) .../wp-blog-header.php:16
4 0.3736 4512552 WP->main( ) .../functions.php:955
5 0.3754 4506576 WP->query_posts( ) .../class-wp.php:735
6 0.3754 4506632 WP_Query->query( ) .../class-wp.php:617
7 0.3754 4506632 WP_Query->get_posts( ) .../class-wp-query.php:3248
8 0.3778 4541440 apply_filters_ref_array( ) .../class-wp-query.php:3007
9 0.3778 4541440 WP_Hook->apply_filters( ) .../plugin.php:244
10 0.3779 4542944 relevanssi_query( ) .../class-wp-hook.php:300
11 0.3779 4542968 relevanssi_do_query( ) .../search.php:49
12 0.3804 4544712 relevanssi_search( ) .../search.php:1322
What if you just add a field parameter to your tax_query? There should be one, after all.
I can make Relevanssi copy WP behaviour and assume term_id if nothing is provided, but I guess it doesn’t hurt if you’re explicit with your parameters.
imho it’s an inaccurate assumption to check if $tax_query is an array and assume it is a result of your last tax_query condition when the previous two also create arrays. But providing a field param myself should work for my needs.
Thanks.
I’m no sure what you mean here, could you elaborate? Do you mean the $tax_query can contain something else than a tax_query? What do you mean with “previous two”?
Thanks for your interest. I’ll attempt to explain in better detail. But first, my fix required two things.
- 1.
'field' => 'term_id' was required for each of my user-created tax queries.
- 2. I had to prevent any empty tax queries (arrays containing only a relation item) from being merged in.
Primarily, my issue is that 'field' is not a required parameter natively as it defaults to 'term_id' but Relevanssi requires it. Imho that should not be the case.
As far as what I meant earlier about “previous two”: in relevanssi/lib/search.php ~line 1021, you start to assemble a $tax_query array. Within that block there are 4 conditions.
- Tax query is empty so remove it
- User-created tax query, loop over and push non-relation values to
$tax_query
- Created by WP, loop over
'queries' and push to $tax_query
- attempt to collect categories and tags into
$tax_query
Conditions 2 & 3 fully assume that a 'field' param is present so when relevanssi_search() gets ahold of it, ~around line 89 there is merely a check for wether $tax_query is an array or not and if so, attempts to reference each $row‘s [‘field’] property. But the only way [‘field’] is guaranteed to exist is if the 4th condition was met. I haven’t tested condition 3 but I assume WP supplies the ‘field’ prop but there’s no guarantee a user will.
I hope that clears it up. Thanks.
Making field default to term_id is an obvious fix, and I’ll switch to using terms to check whether a row is a relation row or an actual tax_query row, since terms is definitely going to appear.
Your post has some code that breaks the layout of the page, by the way.