How to correctly escape query variables to be used in WP_Query

The function for the pre_get_posts action uses a WP_Query object (http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts)

When using functions such as get_posts or classes such as WP_Query and WP_User_Query, WordPress takes care of the necessary sanitization in querying the database. However, when retrieving data from a custom table, or otherwise performing a direct SQL query on the database – proper sanitization is then up to you.

Code Tuts+: Data Sanitization and Validation With WordPress

So in this case, you do not have to escape the query vars.

Leave a Comment