admin管理员组文章数量:1327471
I've used pre_user_query
to edit the actual sql query and it works wonderfully.
Now I'm trying to work with pre_get_posts
and its not at all the same thing. I need to do an INNER JOIN.. In this function it seems to only accept things like $query->set('meta_query',$meta_query);
which is too simple... The setting doesn't allow me to add a JOIN clause and then use it in a WHERE clause.. which is what I need to do.
Am I using the wrong function? Is there a pre_posts_query
that exists instead?? What are others doing here? Any guidance will be super appreciated!
I've used pre_user_query
to edit the actual sql query and it works wonderfully.
Now I'm trying to work with pre_get_posts
and its not at all the same thing. I need to do an INNER JOIN.. In this function it seems to only accept things like $query->set('meta_query',$meta_query);
which is too simple... The setting doesn't allow me to add a JOIN clause and then use it in a WHERE clause.. which is what I need to do.
Am I using the wrong function? Is there a pre_posts_query
that exists instead?? What are others doing here? Any guidance will be super appreciated!
1 Answer
Reset to default 0The pre_get_posts
function is a simple query modifier for general "post" queries. If you're looking to modify the SQL directly for these query I suggest using the post_clauses
hook. This hook passes an array of SQL clauses such as:
$sql['where']
and sql['join']
Here you can inject your own custom SQL into the specific clauses. That being said, if you are truly writing something custom it might be beneficial to circumvent WordPress entirely and just use $wpdb
to grab your results.
本文标签: wp querypreuserquery vs pregetposts
版权声明:本文标题:wp query - pre_user_query vs pre_get_posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742209357a2433418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
INNER JOIN
– Tom J Nowell ♦ Commented Aug 5, 2020 at 15:56pre_user_query
is not equivalent topre_get_posts
, there is apre_get_users
– Tom J Nowell ♦ Commented Aug 5, 2020 at 15:56