Title: Custom Callback Query?
Last modified: February 28, 2018

---

# Custom Callback Query?

 *  Resolved [aslynn](https://wordpress.org/support/users/anyalynn/)
 * (@anyalynn)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/custom-callback-query/)
 * I am looking for a way to limit the total number of posts returned by the query(
   not the # per page). Since there doesn’t seem to be an easy way to do this, I
   tried to create a custom callback function that would at least limit them going
   back 2 months. I tried creating this function (I assume that I put this in my
   functions.php?)
 *     ```
       function qw_date_filter_callback($args, $filter){
       	$args = array(
       	'date_query' => array(
       		array(
       			'after'     => 'January 1st, 2018',
       			'before'    => array(
       				'year'  => 2018,
       				'month' => 3,
       				'day'   => 28,
       			),
       			'inclusive' => true,
       		),
       	  ),
       	);
   
         return $args;
   
       }
       ```
   
 * I tried using it as a filter in both a callback function and in the Post_ID filter
   like this: `function qw_date_filter_callback($args, $filter){ return $args; }`
 * As just a callback function I still get all of the posts. As a callback for the
   Post_IDs inclusive, I get no posts.
 * I must not understand how to use this function and I’m hoping someone might know.
 * Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Jonathan Daggerhart](https://wordpress.org/support/users/daggerhart/)
 * (@daggerhart)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/custom-callback-query/#post-10024624)
 * Hi [@anyalynn](https://wordpress.org/support/users/anyalynn/),
 * Your code is really close to working, I’ll try to fill in the gaps.
 * **Should this go in your functions.php?** – It can! The active theme’s functions.
   php are loaded very early in WordPress bootstrap. A better approach would be 
   to put this code into a plugin, so that it would survive a future theme update
   or change. But in the theme’s functions.php will work.
 * Here a working version of your code:
 *     ```
       function qw_date_filter_callback($args, $filter){
       	$args['date_query'] = array(
       		array(
       			'after'     => 'January 1st, 2018',
       			'before'    => array(
       				'year'  => 2018,
       				'month' => 3,
       				'day'   => 28,
       			),
       			'inclusive' => true,
       		),
       	);
   
       	return $args;
       }
       ```
   
 * The main difference is that it doesn’t replace the entire $args array, it just
   adds the `date_query` key and values.
 * Inside of Query Wrangler, in the callback field you only need to provide the 
   name of your function. In this case, just type `qw_date_filter_callback` into
   the text field on the filter.
 * That should get you going! Let me know if anything is unclear or you have further
   trouble.
 *  Thread Starter [aslynn](https://wordpress.org/support/users/anyalynn/)
 * (@anyalynn)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/custom-callback-query/#post-10025100)
 * Thank you so much. It is working now.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom Callback Query?’ is closed to new replies.

 * ![](https://ps.w.org/query-wrangler/assets/icon-256x256.jpg?rev=3279076)
 * [Query Wrangler](https://wordpress.org/plugins/query-wrangler/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/query-wrangler/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/query-wrangler/)
 * [Active Topics](https://wordpress.org/support/plugin/query-wrangler/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/query-wrangler/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/query-wrangler/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [aslynn](https://wordpress.org/support/users/anyalynn/)
 * Last activity: [8 years, 3 months ago](https://wordpress.org/support/topic/custom-callback-query/#post-10025100)
 * Status: resolved