Want to use wp_get_current_user() in query filter

since the query filter is “applied to all queries (at least all queries run after plugins are loaded)” as stated here in the wordpress codex you should do a further test to make sure that you are in the query you want to be. Perhaps a certain query or queries is/are run before the one(s) you are targeting and this is why the function isn’t loaded yet.

Possible options:

  • You could check that the function wp_get_current_user() exists before using it.
  • You could check is_user_logged_in(), but you may still need to check that this function exists as well
  • maybe you need to use a filter that runs at a later time, I don’t know exactly why you chose this filter though, perhaps this isn’t an option for you.