You may want to hook somewhere in the gazillion hooks available in wp-includes/query.php
.
I would suggest something like this:
function my_always_get_post_custom( $posts ) {
for ( $i = 0; $i < count($posts); $i++ ) {
$custom_fields = get_post_custom( $posts[$i]->ID );
$posts[$i]->custom_fields = $custom_fields;
}
return $posts;
}
add_filter( 'the_posts', 'my_always_get_post_custom' );
In this way you will always have your posts custom fields at hand in your $post
object without having to bother to look for them every time you are setting up a loop. From now on, you can just access them using $post->custom_fields
as a multi-dimensional array
.
Related Posts:
- WP_Query – Order results by meta value
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Filter WP_Query for posts having a certain meta-value
- Can I query custom meta data through WP_Query
- Meta Query with AND & OR?
- How do I search an array stored in a custom-field using WP_Query?
- How do I order by multiple custom fields using wp_query?
- Trying to perform complex custom field query with order by set to field value
- Query meta field using between
- Order Posts by Closest Numeric Values
- 2 orderby in wp_query with 2 custom fields
- Can serialized arrays in DB be matched against serialized arrays with meta_query?
- How to get a meta value from all post
- Compare meta_query decimals not working right
- WP_Query multiple use of relation and/or
- Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’
- Using OR in WP_Query negates the “NOT EXISTS” compare
- WP_query : meta_key with custom rule for specific value
- How can I combine meta_query queries?
- How to filter a dd/mm/yyyy date from a custom field in a query
- Using WP Query to search by multiple meta fields
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Compare WP Custom Field date
- Sort by posts that have a featured image?
- WP_Query display next custom post from today’s date
- Order by value in serialized custom field
- $wp_query meta_key naming issue [closed]
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- Meta_query and numeric comparison [closed]
- Adding Custom Fields to Search
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Multiple relationships in a query
- WP Query Returning All Posts
- How do I use wp_query for WordPress search?
- Meta query with timestamp using WP_query
- Conditional custom field query
- Order query by meta_value with multiple custom fields
- Auto Populate Custom Field with Complex Value That Increase by One?
- Custom WP_Query for WordPress Search Results with meta_query
- Meta Query And/Or
- How to combine custom fields to make one order-able value
- Passing meta_box string to post__in?
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- meta_value and meta_key filtering returning no posts [closed]
- Select custom posts by meta_value and sort by a different meta value
- Can’t query by meta_key
- Adding custom field and querying from post table
- Meta query relation ‘OR’ not working as expected
- The best way to collision check in WP
- WP_query multiple custom fields not working
- Custom Query Fields – Altering Meta Value
- How to query for posts with either one or another custom field
- Multiple Custom Field Query
- How to update custom field of a posts in a particular category
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- WP Query multiple select form – meta_query help
- How to Order Posts by Custom Fields?
- WP_Query based on multiple metadata comparisons
- Complex WP_Query Using Post Date And Post Meta
- Display posts where date field matches current month?
- Show posts containing or not custom field
- Display agents (custom post type) alphabetically, except one who always shows last
- Query posts by Custom Meta (checkbox) & Genesis Grid Loop
- Advanced Custom Fields: how do I check to see if a value is set in an field? [closed]
- Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
- getting all values for a custom field key (cross-post)
- How to add a custom field in the advanced menu properties?
- Custom query with orderby meta_value of custom field
- How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?
- Using meta query (‘meta_query’) with a search query (‘s’)
- Can I exclude a post by meta key using pre_get_posts function?
- Add validation and error handling when saving custom fields?
- Can wp_query return posts meta in a single request?
- Multiple orderby values in WP_Query
- Show Custom Fields in Quick Edit
- Where are custom field values stored in the database
- Validating Custom Meta Box Values & Required Fields
- Max length of meta_value
- Add custom fields to wp native gallery settings
- How to fix missing custom fields after upgrading to WordPress 4.8.1?
- How to enable custom fields for pages (if not a bad practice)?
- How can I add extra attribute in the ‘Page Attribute’ section in wp-admin for pages?
- Is there a way to set default custom fields when creating a post?
- Custom post meta field effect on the performance on the post
- How to get custom post meta using REST API
- Custom field/meta populated by dropdown of existing posts?
- Difference between meta keys with _ and without _ [duplicate]
- Filter by one custom field, order by another?
- Is there any action filter/hook for validating a custom field before publishing the post?
- Remove Dimension from wp_get_attachment_image
- Orderby meta_value only returns posts that have existing meta_key
- Underscores in custom fields
- What is the index [0] for on post meta fields?
- What is “meta_input” parameter in wp_insert_post() used for?
- Meta query with string starting like pattern
- Query Posts or Get Posts by custom fields, possible?
- How to enable revisions for post meta data?
- compare meta_query in get_posts arguments
- Sortable Custom Columns in User Panel (users.php)?