0

Is there a similar replacement of the hook posts_where for comments (WP_Comment_Query)? I need to modify the where clause for a comments query like it is shown in this tutorial (“4. Sub custom field values”) for posts. The only hook I found is comments_pre_query, but the property $query->meta_query_clauses[ 'where' ] is protected.

3
  • the article you linked to seems to have been written by someone unaware of the LIKE operator in meta queries, likely because it is very old and at least 10 versions of WordPress out of date. I would treat this with a grain of salt, especially when the example uses the incorrect function to cleanup after WP_Query ( it should be wp_reset_postdata not wp_reset_query )
    – Tom J Nowell
    May 20, 2022 at 12:46
  • @TomJNowell Do you have a better idea to query for ACF Repeater field values?
    – Silas_229
    May 20, 2022 at 12:59
  • the problem is how you stored the data, serialized data isn't meant to be queried, and the solution provided is not a full solution, e.g. if you're looking for 100 then 1000 will also match, -100 _100_ 241008 etc. That's on top of post meta already being slow to query for. As an aside were you sent here by other ACF users? 3rd party plugin dev support is offtopic here but there have been a lot of new ACF questions today
    – Tom J Nowell
    May 20, 2022 at 13:09

1 Answer 1

0

Yes, a quick search of developer.wordpress.org reveals comment_feed_where.

Note that this won't work with get_posts unless suppress filters is turned off, and that what you're trying to do is going to be very slow with some unreliability.

There is also comment_clauses:

https://developer.wordpress.org/reference/hooks/comments_clauses/

3
  • I saw that hook, too, but is it also called along with get_comments()/WP_Comment_Query? The documentation mentions WP_Query, not WP_Comment_Query
    – Silas_229
    May 20, 2022 at 12:57
  • there is a separate filter that passes an array of all the clauses
    – Tom J Nowell
    May 20, 2022 at 13:08
  • That works. Thank you!
    – Silas_229
    May 20, 2022 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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