This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
comments_template_top_level_query_args filter
Example 1: Modify Top Level Query Args
Let’s say you want to modify the top-level query arguments for your comments template. You can easily do this by defining a function and hooking it up like this:
function weplugins_modify_comments_template_top_level_query_args_defaults($top_level_args) { // Update the $top_level_args variable according to your website requirements. return $top_level_args; } // Add the filter add_filter( "comments_template_top_level_query_args", "weplugins_modify_comments_template_top_level_query_args_defaults", 10, 1 );
Example 2: Removing the Hook Callback
Sometimes, you might need to remove a registered hook. Here’s how you can do it:
remove_filter( "comments_template_top_level_query_args", "weplugins_modify_comments_template_top_level_query_args_defaults", 10, 1 );
Make sure you provide the same callback function name, priority, and number of arguments when removing the hook callback.
Example 3: Applying the Filter
Below is an example of how you can apply this hook:
apply_filters( 'comments_template_top_level_query_args', array $top_level_args );
- $top_level_args: (array) The top-level query arguments for the comments template.
- ‘count’: (bool) Whether to return a comment count.
- ‘orderby’: (string|array) The field(s) to order by.
- ‘post_id’: (int) The post ID.
- ‘status’: (string|array) The comment status to limit results by.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.