WordPress错误:警告非法偏移

时间:2015-01-09 13:43:40

标签: javascript php wordpress warnings

我在wordpress上的目录网站上工作,当我尝试搜索选项时,我收到此错误:

警告:非法字符串偏移'字段'在第27行的/home/dalilouk/public_html/wp-content/themes/directory/header.php

警告:非法字符串偏移'字段'在第33行的/home/dalilouk/public_html/wp-content/themes/directory/header.php

搜索的结果始终是"没有找到任何内容"。

这是第27行的header.php的代码:

<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>

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

它不是PHP源代码。你刚刚在浏览器中打开了php,所以你发布的是PHP脚本输出。您必须在某个编辑器中打开真正的.php文件,并向我们显示源代码:)

根据你的问题 - 这不是错误,它是关于调用变量的警告,它在某些点上没有设置。所以你的脚本仍然有效,但是你的表单可能有错误的字段名称要发送,所以你的php脚本无法找到你想要搜索的数据,因为找不到那个特定的变量。