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.
posts_fields filter
Filters the SELECT clause of the query.
apply_filters_ref_array( 'posts_fields', string $fields, WP_Query $query )
Description
This is a filter hook, and it modifies the SELECT clause of the query. It consists of two parameters: $fields and $query. The posts_fields filter controls which database fields will be returned in the query, and it usually defaults 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
To run the hook, copy the example below.
Example 1: Basic Usage of posts_fields Filter
This example shows how to apply the posts_fields filter in a basic scenario.
$array = apply_filters( 'posts_fields', $array ); if ( !empty( $array ) ) { // everything has led up to this point... }
Example 2: Adding a Hook Callback
The following example demonstrates how to add a callback function to the posts_fields filter.
// define the posts_fields callback function weplugins_filter_posts_fields( $array ) { // make filter magic happen here... return $array; }; // add the filter add_filter( 'posts_fields', 'weplugins_filter_posts_fields', 10, 1 );
Example 3: Removing a Hook Callback
To remove a callback function from the posts_fields filter, use the example below.
// remove the filter remove_filter( 'posts_fields', 'weplugins_filter_posts_fields', 10, 1 );
Contact Us
If you need customization or have any questions, feel free to contact us.
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.