• The WP_Query->fill_query_vars() method defines all the query variables that WordPress understands by default:
    https://core.trac.www.ads-software.com/browser/tags/4.7/src/wp-includes/class-wp-query.php#L564

    Why is the output array not filtered before it is returned? It seems that it would be a very useful place for _removing_ specific query variables that a website would prefer to not have defined, such as “author”.

    I am considering a patch to WordPress Core which would filter this array, but since it seems so obvious I would like to understand more about why the filter doesn’t exist yet before submitting the patch.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I’ve no special insight into the reasoning of core developers, this is entirely speculation on my part. I’m speaking for myself here, not representing the Support Team as a moderator.

    Placing such a filter would complicate how WP_Query::parse_query() works because we could no longer assume any query var actually exists, requiring additional checks before using any one of them. Since the query vars can be modified in “parse_query” and “pre_get_posts”, having a filter like you suggest isn’t absolutely required to remove a query var before the query actually runs.

    Granted, such a filter would prevent some unnecessary parsing, but that gain is offset by the need to verify the query var still exists prior to parsing. Since reasonable alternatives exist, I would say the justification for this filter is weak at best.

    Have you tried searching Trac for a similar proposal? Perhaps we’ve already been through this. If not, you are free to submit your proposal. Then you would get feedback from people actually responsible for core code instead of random forum members like me. Be prepared for pushback along the lines that I’ve mentioned. Perhaps there are factors I’ve failed to consider. We can discuss further if you like, but this is not where you need to make your case.

    Thread Starter Dotan Cohen

    (@dotancohen)

    Thank you, in fact the argument about having to check for the existence of each query var is strong enough to discourage the idea already. As you mention, many or most of the use cases can already be handled with extant hooks, albeit a bit more involved but doable.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Why is there no filter on fill_query_vars() output?’ is closed to new replies.