dousui6193 2019-05-08 18:29
浏览 48

有没有办法在我的Wordpress / Woocommerce网站上解决这个“试图获取非对象的属性'分类”错误?

I'm setting up a new Wordpress/Woocommerce website using the Avada theme. The site is not live yet.

The store has custom product taxonomies, and as some of the taxonomy names contain a comma I've had to find a code snippet to do a workaround in PHP so that the comma is displayed without splitting the taxonomy name into two separate names (eg. Bouncy Balls, Putty and Slime). The PHP I found has replaced a double dash (--) with a comma in the front end, which appears to work as it should.

My problem is, that since I have added this code I'm getting an error at the top of the page on individual product pages:

Notice: Trying to get property 'taxonomy' of non-object in /var/sites/a/mywebsite.com/public_html/wpnew/wp-content/themes/Avada-Child-Theme/functions.php on line 32

Line 32 code:

if( $tag_arr->taxonomy == 'post_tag' && strpos( $tag_arr->name, '--' ) ) {

All of the code I inserted into functions.php is below.

I'm not sure what to try to fix this as this is all new to me and I'm learning as I go along. I have very little knowledge of PHP, besides the snippet I have found online and placed here.

if( !is_admin() ){
    function comma_tag_filter( $tag_arr ){
        $tag_arr_new = $tag_arr;
        if( $tag_arr->taxonomy == 'post_tag' && strpos( $tag_arr->name, '--' ) ) {
            $tag_arr_new->name = str_replace( '--', ', ', $tag_arr->name );
        }
        return $tag_arr_new;    
    }
    add_filter( 'get_post_tag', 'comma_tag_filter' );

    function comma_tags_filter( $tags_arr ) {
        $tags_arr_new = array();
        foreach( $tags_arr as $tag_arr ) {
            $tags_arr_new[] = comma_tag_filter( $tag_arr );
        }
        return $tags_arr_new;
    }
    add_filter( 'get_terms', 'comma_tags_filter' );
    add_filter( 'get_the_terms', 'comma_tags_filter' );
}

I expected this code to work without errors, but I have the error message at the top of the product pages.

Thanks for any help

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch