Forums

[Plugin: Yet Another Related Posts Plugin] Function related_entries_exist() not working properly (7 posts)

  1. toadloading
    Member
    Posted 2 years ago #

    Hi mitchoyoshitaka, I wrote a customized YARPP multi-widget based on the new widget API of WordPress version2.8. According to design, this widegt should only be presented once current entry has some related items, otherwise it should just not appear, instead of saying "No related entries.", following is the source code in the output section:

    function widget( $args, $instance ) {
    
      extract( $args, EXTR_SKIP );
      $title = apply_filters('widget_title', $instance['title'] );
    
      if ( related_entries_exist() ) :
        echo $before_widget;
        if ( $title )
          echo "\n\t\t\t" . $before_title . $title . $after_title;
        echo related_entries();
        echo $after_widget;
      endif;
    
    }

    But the related_entries_exist() seems always return true, even when related_entries() returns No related entries.
    Could you figure out why this happens? Is the related_entries_exist() can only exists in The Loop? Or should I give it an argument of current entry's ID?

    I'm sorry to hear of your family emergency, wish you can answer my question when you get back.

  2. @toadloading - unfortunately these related_* functions won't work outside of The Loop. Does that explain the issue?

  3. toadloading
    Member
    Posted 2 years ago #

    @mitchoyoshitaka - Thanks for your explaination, but could you give me some advice for correct implementation of my widget's design? Or, perhaps you will be interesting for developing a multiwidget of your plugin? :)

  4. toadloading
    Member
    Posted 2 years ago #

    Interestingly, the related_entries() works pretty good in singular pages (single post or single page), you can check my demonstration.

  5. The exists functions were rewritten in a recent update so should be working now.

  6. toadloading
    Member
    Posted 1 year ago #

    @mitchoyoshitaka - Thank you! I have almost forgot this topic, many thanks for your great YARPP plugin and your diligent work!

  7. @toadloading - glad to hear it's working. :)

Topic Closed

This topic has been closed to new replies.

About this Topic