Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use posts_fields_request filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
November 20, 2022
5 minutes read

posts_fields_request filter

Filters the SELECT clause of the query.

apply_filters_ref_array('posts_fields_request', string $fields, WP_Query $query)

Description

This is a filter hook that modifies the SELECT clause of the query. It consists of two parameters: one is $fields, and the second is $query. The posts_fields_request filter controls which database fields will be returned in the query, and it seems to default to all fields from the posts table.

Parameters

  • $fields: (string) The SELECT clause of the query.
  • $query: (WP_Query) The WP_Query instance (passed by reference).

Live Example

Basic Usage

To run the hook, copy the example below.

	$array = apply_filters('posts_fields_request', $array);
	if (!empty($array)) {
		// everything has led up to this point...
	}
	

Adding a Hook Callback

The following example is for adding a hook callback.

	// define the posts_fields_request callback 
	function weplugins_filter_posts_fields($array) {
		// make filter magic happen here...
		return $array;
	}
	 
	// add the filter 
	add_filter('posts_fields_request', 'weplugins_filter_posts_fields', 10, 1);
	

Removing a Hook Callback

To remove a hook callback, use the example below.

	// remove the filter 
	remove_filter('posts_fields_request', 'weplugins_filter_posts_fields', 10, 1);
	

Access Premium WordPress Plugins

Contact Us

If you need customization or have any questions, feel free to Contact Us.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.