WordPress action hook · part of WordPress core

pre_get_posts

A WordPress core action that 4 plugins also fire themselves, running on 8,130+ sites between them.

“Fires after the query variable object is created, but before the actual query is run.”

How to use pre_get_posts

It's an action: your callback runs at that point. Nothing needs to be returned. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_action( 'pre_get_posts', function( $arg1 ) {
	// Your code runs here.
}, 10, 1 );

Argument names come from ALD's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

4 plugins that fire pre_get_posts

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. ALD icon ALD8,000+ installs do_action_ref_array( 'pre_get_posts', array( &$this ) ) includes/ali-product-query.php:164
  2. ChinaDS icon ChinaDS100+ installs do_action_ref_array( 'pre_get_posts', array( &$this ) ) inc/taobao-post-query.php:277
  3. HANDMADE icon HANDMADE30+ installs do_action_ref_array( 'pre_get_posts', array( &$this ) ) includes/class/handmade-post-query.php:329
  4. Gospel Resource Hub icon Gospel Resource HubFewer than 10 installs do_action_ref_array( 'pre_get_posts', array( &$this ) ) includes/class-grh-query.php:25

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.