• Copilot log snippet of debugging why my site would not return any results for the word elementor:

    I hope this can be addressed in the next version. Thanks 🙂

    [04-Sep-2025 04:57:01 UTC] PHP Warning: Undefined array key "post_type" in wp-content/plugins/relevanssi/lib/search-query-restrictions.php on line 81

    Excellent! This additional debug info reveals even more details about what was happening:

    ## **Key Findings:**

    1. **Search post_type setting: (empty)** - This shows that your search query itself wasn't explicitly setting a post type restriction

    2. **PHP Warning in search-query-restrictions.php line 81** - This indicates there's a bug or edge case in Relevanssi's code where it's trying to access
    $params['post_type'] when that key doesn't exist

    ## **The Real Issue:**

    The warning suggests that Relevanssi's internal code was expecting a post_type parameter to exist in the search parameters, but it wasn't set. When this happens, Relevanssi might have been defaulting to some fallback behavior (possibly searching only pages) or encountering an error that caused it to return no results.

    ## **Why Your Fix Works:**

    Your fix works because by explicitly unsetting $params['post_type'] (even when it doesn't exist), you're ensuring that Relevanssi's search logic doesn't encounter this undefined key issue and falls back to searching all indexed post types.

    ## **Improved Fix to Address the Warning:**

    Here's a more robust version of your fix that also handles the undefined key properly:

    php<br><br>add_filter('relevanssi_search_params', 'fix_relevanssi_post_type_issue');<br><br>function fix_relevanssi_post_type_issue($params) {<br><br>    <em>// Ensure post_type is properly handled - either remove it entirely</em><br><br>    <em>// or set it to a safe default</em><br><br>    <em>if</em> (isset($params&#091;'post_type'])) {<br><br>        unset($params&#091;'post_type']);<br><br>    }<br><br>    <em>// Alternative: explicitly set to search posts and pages</em><br><br>    <em>// $params&#091;'post_type'] = array('post', 'page');</em><br><br>    <em>return</em> $params;<br><br>}<br><br>

    ## **Root Cause Analysis:**

    This appears to be either:

    1. **A bug in Relevanssi** where it doesn't properly handle cases where post_type isn't set in the search parameters

    2. **A compatibility issue** between your WordPress setup and Relevanssi's expectations

    3. **An edge case** in Relevanssi's search-query-restrictions.php that doesn't account for missing post_type parameters

    ## **Recommendation:**

    Your current fix is working perfectly and is actually a good solution. You might want to:

    1. **Keep your current fix** - it's solving the problem effectively

    2. **Report this to Relevanssi developers** - the PHP warning suggests there's a bug in their code at line 81 of search-query-restrictions.php

    3. **Consider the improved version above** - it's more defensive and handles edge cases better

    **Great debugging work!** You've not only solved your search issue but also potentially discovered a bug in the Relevanssi plugin itself. 🕵️‍♂️✨
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mikko Saari

    (@msaari)

    This error message about missing array key is caused by the relevanssi_search_params filter function. Remove the function, and the missing array key warning should go away. Your current fix is not solving the problem, it’s causing it.

    So, let’s forget about the suggestions from Copilot, as they’re useless, and let’s go step back. What is the actual problem you’re trying to solve here?

    Thread Starter Shivanand Sharma

    (@varun21)

    My site would not return any results for the word elementor. That code snippet fixed it.

    Plugin Author Mikko Saari

    (@msaari)

    So, you want to get results, but don’t get anything, and then you remove the post_type parameter and you get results. That suggests you have a post_type parameter in the search that doesn’t match what you want. The solution is to either change the value to something useful, or to remove the parameter completely – that’s often the best solution with Relevanssi.

    So, you’re on the right track, but relevanssi_search_params is not the correct hook: as you’ve seen, you can’t remove parameters in that hook. Try this:

    add_filter( 'relevanssi_modify_wp_query', function( $query ) {
    $query->set( 'post_type', 'any' );
    return $query;
    } );

    Thread Starter Shivanand Sharma

    (@varun21)

    And these are the settings. No permutation / combination would help to get any results for /?s=elementor

    grep -rni "relevanssi" .
    ./wp_options.csv:2783:"271","relevanssi_admin_search","on","off"
    ./wp_options.csv:2784:"272","relevanssi_bg_col","#ffaf75","yes"
    ./wp_options.csv:2785:"273","relevanssi_cat",,"yes"
    ./wp_options.csv:2786:"274","relevanssi_class","relevanssi-query-term","yes"
    ./wp_options.csv:2787:"275","relevanssi_comment_boost","0.75","on"
    ./wp_options.csv:2788:"276","relevanssi_content_boost","1","on"
    ./wp_options.csv:2789:"277","relevanssi_css","text-decoration: underline; text-color: #ff0000","yes"
    ./wp_options.csv:2790:"278","relevanssi_db_version","9","yes"
    ./wp_options.csv:2791:"279","relevanssi_default_orderby","relevance","yes"
    ./wp_options.csv:2792:"280","relevanssi_disable_or_fallback","off","yes"
    ./wp_options.csv:2793:"281","relevanssi_exact_match_bonus","on","yes"
    ./wp_options.csv:2794:"282","relevanssi_excat",,"yes"
    ./wp_options.csv:2795:"283","relevanssi_excerpt_allowable_tags",,"yes"
    ./wp_options.csv:2796:"284","relevanssi_excerpt_custom_fields","off","yes"
    ./wp_options.csv:2797:"285","relevanssi_excerpt_length","30","on"
    ./wp_options.csv:2798:"286","relevanssi_excerpt_type","words","yes"
    ./wp_options.csv:2799:"287","relevanssi_excerpts","on","yes"
    ./wp_options.csv:2800:"288","relevanssi_exclude_posts",,"yes"
    ./wp_options.csv:2801:"289","relevanssi_expand_shortcodes","on","yes"
    ./wp_options.csv:2802:"290","relevanssi_extag","0","yes"
    ./wp_options.csv:2803:"291","relevanssi_fuzzy","never","on"
    ./wp_options.csv:2804:"292","relevanssi_highlight","strong","yes"
    ./wp_options.csv:2805:"293","relevanssi_highlight_comments","off","yes"
    ./wp_options.csv:2806:"294","relevanssi_highlight_docs","off","yes"
    ./wp_options.csv:2807:"295","relevanssi_hilite_title","off","on"
    ./wp_options.csv:2808:"296","relevanssi_implicit_operator","OR","on"
    ./wp_options.csv:2809:"297","relevanssi_index_author","on","off"
    ./wp_options.csv:2810:"298","relevanssi_index_comments","all","off"
    ./wp_options.csv:2811:"299","relevanssi_index_excerpt","on","off"
    ./wp_options.csv:2812:"300","relevanssi_index_fields","all","off"
    ./wp_options.csv:2813:"301","relevanssi_index_limit","500","yes"
    ./wp_options.csv:2814:"302","relevanssi_index_post_types","a:3:{i:0;s:4:""post"";i:1;s:4:""page"";i:2;s:5:""bogus"";}","yes"
    ./wp_options.csv:2816:"304","relevanssi_indexed","done","yes"
    ./wp_options.csv:2817:"305","relevanssi_log_queries","on","yes"
    ./wp_options.csv:2818:"306","relevanssi_log_queries_with_ip","on","yes"
    ./wp_options.csv:2819:"307","relevanssi_min_word_length","3","on"
    ./wp_options.csv:2820:"308","relevanssi_omit_from_logs",,"yes"
    ./wp_options.csv:2821:"309","relevanssi_polylang_all_languages","off","yes"
    ./wp_options.csv:2822:"310","relevanssi_punctuation","a:4:{s:6:""quotes"";s:7:""replace"";s:7:""hyphens"";s:7:""replace"";s:10:""ampersands"";s:7:""replace"";s:8:""decimals"";s:6:""remove"";}","yes"
    ./wp_options.csv:2823:"311","relevanssi_respect_exclude","on","yes"
    ./wp_options.csv:2824:"312","relevanssi_show_matches","off","on"
    ./wp_options.csv:2825:"313","relevanssi_show_matches_text","(Search hits: %body% in body, %title% in title, %categories% in categories, %tags% in tags, %taxonomies% in other taxonomies, %comments% in comments. Score: %score%)","yes"
    ./wp_options.csv:2826:"314","relevanssi_synonyms","a:1:{s:5:""en_US"";s:0:"""";}","yes"
    ./wp_options.csv:2827:"315","relevanssi_throttle","on","yes"
    ./wp_options.csv:2828:"316","relevanssi_throttle_limit","500","yes"
    ./wp_options.csv:2829:"317","relevanssi_title_boost","5","on"
    ./wp_options.csv:2830:"318","relevanssi_txt_col","#ff0000","yes"
    ./wp_options.csv:2831:"319","relevanssi_word_boundaries","on","yes"
    ./wp_options.csv:2832:"320","relevanssi_wpml_only_current","off","on"
    ./wp_options.csv:2840:"339","relevanssi_doc_count","169","yes"
    ./wp_options.csv:2854:"841","relevanssi_trim_logs","700","yes"
    ./wp_options.csv:3236:"32965","relevanssi_stopwords","a:1:{s:5:""en_US"";s:1908:""a,about,above,across,after,afterwards,again,against,all,almost,alone,along,already,also,although,always,am,among,amongst,amoungst,amount,an,and,another,any,anyhow,anyone,anything,anyway,anywhere,are,around,as,at,back,be,became,because,become,becomes,becoming,been,before,beforehand,behind,being,below,beside,besides,between,beyond,bill,both,bottom,but,by,call,can,cannot,cant,co,con,could,couldnt,cry,de,describe,detail,do,done,down,due,during,each,eg,eight,either,eleven,else,elsewhere,empty,enough,etc,even,ever,every,everyone,everything,everywhere,except,few,fifteen,fifty,fill,find,fire,first,five,for,former,formerly,forty,found,four,from,front,full,further,get,give,go,had,has,hasnt,have,he,hence,her,here,hereafter,hereby,herein,hereupon,hers,herself,him,himself,his,how,however,hundred,ie,if,in,inc,indeed,interest,into,is,it,its,itself,keep,last,latter,latterly,least,less,ltd,made,many,may,me,meanwhile,might,mill,mine,more,moreover,most,mostly,move,much,must,my,myself,name,namely,neither,never,nevertheless,next,nine,no,nobody,none,noone,nor,not,nothing,now,nowhere,of,off,often,on,once,one,only,onto,or,other,others,otherwise,our,ours,ourselves,out,over,own,part,per,perhaps,please,put,rather,re,same,see,seem,seemed,seeming,seems,serious,several,she,should,show,side,since,sincere,six,sixty,so,some,somehow,someone,something,sometime,sometimes,somewhere,still,such,system,take,ten,than,that,the,their,them,themselves,then,thence,there,thereafter,thereby,therefore,therein,thereupon,these,they,thickv,thin,third,this,those,though,three,through,throughout,thru,thus,to,together,too,top,toward,towards,twelve,twenty,two,un,under,until,up,upon,us,very,via,was,we,well,were,what,whatever,when,whence,whenever,where,whereafter,whereas,whereby,wherein,whereupon,wherever,whether,which,while,whither,who,whoever,whole,whom,whose,why,will,with,within,without,would,yet,you,your,yours,yourself,yourselves"";}","yes"
    ./wp_options.csv:3523:"238741","relevanssi_terms_count","25893","off"

    • This reply was modified 9 months ago by Shivanand Sharma. Reason: typo in query
    Plugin Author Mikko Saari

    (@msaari)

    Does setting the post_type to any help?

    Thread Starter Shivanand Sharma

    (@varun21)

    Previous post in which I shared the settings has been held for moderation.

    Your code does work as does the previous one I shared except that it throws that warning in the debug.log. Surprisingly the default post_type is only set to page. Why???

    add_filter( 'relevanssi_modify_wp_query', function( $query ) {
    error_log( $query->get("post_type") ); //outputs page
    $query->set( 'post_type', 'any' );
    return $query;
    } );
    Plugin Author Mikko Saari

    (@msaari)

    I have no idea – that’s something your theme or something else on your site does. Relevanssi has no opinion on the topic.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Undefined array key “post_type”’ is closed to new replies.