在wordpress和SQL查询之间注入中间件的最佳方法是什么?

时间:2015-08-05 15:36:09

标签: php mysql sql-server wordpress wordpress-plugin

我正在寻找从所有使用默认wp_query的插件获取所有wordpress数据库请求的方法。我需要按模式过滤所有查询,如果匹配,我需要将此语句查询到另一个数据库 请建议我如何监听所有SQL查询?或者有另一种方法可以做到这一点?

2 个答案:

答案 0 :(得分:1)

如果您希望在SQL配置中取消注释日志行

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.

log = /var/log/mysql/mysql.log /* Line to uncomment */ 

您可以将日志文件放在任何地方并使用php阅读它以获得您想要的内容。

或者您可以使用插件方式

https://wordpress.org/plugins/query-recorder/

答案 1 :(得分:0)

当然你可以使用“pre_get_posts”钩子,为你做一些信息。

remicorson.com/modifying-the-current-query-with-pre_get_posts

codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts