WordPress.org

Ready to get started?Download WordPress

Forums

Easy Related Posts
[resolved] Broken when there are no tags (7 posts)

  1. ambrosey
    Member
    Posted 9 months ago #

    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.

    http://wordpress.org/plugins/easy-related-posts/

  2. Vagenas Panagiotis
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  3. ambrosey
    Member
    Posted 9 months ago #

    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.

  4. neoseeyou
    Member
    Posted 8 months ago #

    Hello

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

    THanks

  5. Vagenas Panagiotis
    Member
    Plugin Author

    Posted 8 months ago #

    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;
                        }
  6. neoseeyou
    Member
    Posted 8 months ago #

    Thanks you sir for your quick answer

  7. Vagenas Panagiotis
    Member
    Plugin Author

    Posted 8 months ago #

    Resolved as for version 1.5.1. Please confirm it.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.