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!

  • What are you trying to do? It might be more useful to ask about that, there's likely a better option that avoids needing an INNER JOIN – Tom J Nowell Aug 5 at 15:56
  • Also pre_user_query is not equivalent to pre_get_posts, there is a pre_get_users – Tom J Nowell Aug 5 at 15:56

The 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.