• Resolved Alice Brosey

    (@ambrosey)


    When there are no tags for a post, and it is set to have related posts, it is breaking instead of posting a “No Related Posts” or similar message. I am coding a fix for this for a client, but you ought to update the plugin.

    erp_display.php line 149 needs to have a conditional for if get_the_tags is not returning anything.

    same with erp_widget.php line 180.

    I don’t know if those are the only errors of this type (for loop attempting to run on invalid variables) as these are the only ones that affected my specific client’s setup.

    https://www.ads-software.com/plugins/easy-related-posts/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author xdark

    (@xdarkeu)

    This must be a php version specific bug. In php 5.* foreach should not iterate if get_the_tags() returns false. Please tell me your php version you are using.
    In the mean time try foreach((get_the_tags($post->ID)) || NULL as $tag) or foreach(((array)get_the_tags($post->ID)) as $tag).
    Thank you for noticing this.

    Thread Starter Alice Brosey

    (@ambrosey)

    Actually, calling foreach on anything not an array (FALSE is not an array) will usually throw an error. I’m not really sure what you are talking about. Of course it doesn’t iterate, but it *does* throw the error.

    The second of your options, worked smoothly. The server in question was running 5.2.17.

    alpha2

    (@neoseeyou)

    Hello

    As suggest, i try both solution in my ep_widget.php but it break my theme. ANy solution?

    THanks

    Plugin Author xdark

    (@xdarkeu)

    File erp_display.php change lines 148-158
    original:

    $tagAr = array();
                        foreach((get_the_tags($post->ID)) as $tag){
                        	array_push($tagAr,$tag->term_id);
                        }
                        if (empty($tagAr)){
                            return FALSE;
                        }
                        $argu['tag__in'] = $tagAr;
                        if (!empty($tags)){
                            $argu['tag__not_in'] = $tags;
                        }

    modified:

    $tagAr = array();
                        $postTags = get_the_tags($post->ID);
                        if (is_array($postTags)){
                            foreach($postTags as $tag){
    	                    	array_push($tagAr,$tag->term_id);
    	                    }
                        	$argu['tag__in'] = $tagAr;
                        	if (!empty($tags)){
    	                        $argu['tag__not_in'] = $tags;
    	                    }
                        } else {
                        	return FALSE;
                        }

    alpha2

    (@neoseeyou)

    Thanks you sir for your quick answer

    Plugin Author xdark

    (@xdarkeu)

    Resolved as for version 1.5.1. Please confirm it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Broken when there are no tags’ is closed to new replies.