0
votes

I'm working on a directory website on wordpress, when I try the search option I'm getting this error:

Warning: Illegal string offset 'field' in /home/dalilouk/public_html/wp-content/themes/directory/header.php on line 27

Warning: Illegal string offset 'field' in /home/dalilouk/public_html/wp-content/themes/directory/header.php on line 33

And the result of the search is always "nothing found".

This is the code of the header.php from line 27:

<script type="text/javascript">            #line 27
jQuery(document).ready(function($) {

    {ifset $themeOptions->search->searchCategoriesHierarchical}
    var categories = [ {!$categoriesHierarchical} ];
    {else}
    var categories = [                #line 33
    {foreach $categories as $cat}
        { value: {$cat->term_id}, label: {$cat->name} }{if !($iterator->last)},{/if}
    {/foreach}
    ];
    {/ifset}

    {ifset $themeOptions->search->searchLocationsHierarchical}
    var locations = [ {!$locationsHierarchical} ];
    {else}
    var locations = [
    {foreach $locations as $loc}
        { value: {$loc->term_id}, label: {$loc->name} }{if !($iterator->last)},{/if}
    {/foreach}
    ];
    {/ifset}

    var catInput = $( "#dir-searchinput-category" ),
        catInputID = $( "#dir-searchinput-category-id" ),
        locInput = $( "#dir-searchinput-location" ),
        locInputID = $( "#dir-searchinput-location-id" );

    catInput.autocomplete({
        minLength: 0,
        source: categories,
        focus: function( event, ui ) {
            var val = ui.item.label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            catInput.val( val );
            return false;
        },
        select: function( event, ui ) {
            var val = ui.item.label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            catInput.val( val );
            catInputID.val( ui.item.value );
            return false;
        }
    }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li>" )
            .data( "item.autocomplete", item )
            .append( "<a>" + item.label + "</a>" )
            .appendTo( ul );
    };
    var catList = catInput.autocomplete( "widget" );
    catList.niceScroll({ autohidemode: false });

    catInput.click(function(){
        catInput.val('');
        catInputID.val('0');
        catInput.autocomplete( "search", "" );
    });

    locInput.autocomplete({
        minLength: 0,
        source: locations,
        focus: function( event, ui ) {
            var val = ui.item.label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            locInput.val( val );
            return false;
        },
        select: function( event, ui ) {
            var val = ui.item.label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            locInput.val( val );
            locInputID.val( ui.item.value );
            return false;
        }
    }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li>" )
            .data( "item.autocomplete", item )
            .append( "<a>" + item.label + "</a>" )
            .appendTo( ul );
    };
    var locList = locInput.autocomplete( "widget" );
    locList.niceScroll({ autohidemode: false });

    locInput.click(function(){
        locInput.val('');
        locInputID.val('0');
        locInput.autocomplete( "search", "" );
    });


    {ifset $_GET['dir-search']}
    // fill inputs with search parameters
    $('#dir-searchinput-text').val({$searchTerm});
    catInputID.val({$_GET["categories"]});
    for(var i=0;i<categories.length;i++){
        if(categories[i].value == {$_GET["categories"]}) {
            var val = categories[i].label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            catInput.val(val);
        }
    }
    locInputID.val({$_GET["locations"]});
    for(var i=0;i<locations.length;i++){
        if(locations[i].value == {$_GET["locations"]}) {
            var val = locations[i].label.replace(/&amp;/g, "&");
                val = val.replace(/&nbsp;/g, " ").replace(/&#039;/g, "'");
            locInput.val(val);
        }
    }
    {/ifset}

});
</script>

Please help me fix this.

1

1 Answers

0
votes

Its not PHP source code. You just opened that php in browser, so what you posted is that PHP script output. You must open real .php file in some editor, and show us the source code :)

By your question - This is not error, its warning about calling the variable, which is not set on some point. So your script still works, but possibly your form has wrong field name to send, so your php script cannot find out what data you wanna search for, because cannot find that specific variable.