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.
1 Answer
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/
-
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 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
-
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 afterWP_Query
( it should bewp_reset_postdata
notwp_reset_query
)100
then1000
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