0

Specifically in the buddypress forums loop.

I want to be able to alter the SQL so that it returns only specific forums topics. I want to be able to find where the SQL is executed for a specific loop. I might stumble upon on it, but wonder if there is a good way to trace back / debug any and all loops to find the SQL that is generated.

I'm still struggling to understand loops and tags, actions and hooks. So any tips for debugging would be really helpful.

UPDATE: I tell you what I want to do exactly. I want to be able to return forum topics in buddypress forums that meet certain conditions ie I want to return certain forum topics that contain search terms in that topics posts. What is the best way to add those conditions to the forums loop sql.

Thanks

4

1 回答 1

0

如果你真的想使用 sql 然后打开 wp-includes/query.php ,去 functin get_posts。这是一个相当大的功能,所有的魔法都会发生。不要在此处修改任何内容,而是使用它来查看调用了女巫过滤器以及何时调用(例如,在第 1869 行,您将看到$search = apply_filters_ref_array('posts_search', array( $search, &$this ) );,女巫意味着您需要在钩子上使用过滤器posts_search,然后您可以修改 sql 查询,这只是一个例如选择正确的过滤器)。

现在,如果您只是说明在循环开始之前使用query_posts函数会更容易,也是更好的做法。循环通常从您的主题文件开始(搜索 codex.wordpress.org 以获取可用的主题文件,在哪里找到它们以及何时调用女巫)。

于 2011-02-09T18:13:39.137 回答