WordPress.org

Ready to get started?Download WordPress

Forums

Hooks/Filters called from the WP_Query class should be passed the instance (1 post)

  1. Richard Venable
    Member
    Posted 5 years ago #

    I think Hooks/Filters called from the WP_Query class should be passed the instance.

    I was writing a plugin that added some posts to the main query under certain circumstances. However, this was having the side effect of altering the results of widgets such as the Recent Posts widget.

    As it turns out, the Recent Posts widget function creates a new instance of WP_Query. My code was assuming there was only one global instance of WP_Query ($GLOBALS['wp_query']), and was thus using functions like is_home() (which return values from $GLOBALS['wp_query']) inside of my hooks.

    In summary, the 'the_posts' filter (and filters/hooks like it) should pass the instance ($this), because any functions which filter on it can't assume that it is being called using the global instance, and thus can't rely on functions like is_home(), is_archive(), is_search(), etc.

    Anyone have any ideas for some workarounds to get the current instance when it isn't passed to me?

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 5 years ago by Richard Venable
  • This topic is not resolved
  • WordPress version: 2.5.1