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
- Pre-filling custom fields on New Post
- So much data in postmeta
- Show Custom Comment Fields when editing in admin
- Custom Meta Boxes: Store two values in one repeatable field
- Gutenberg Custom Block
- Up/Down voting system for WordPress
- Custom Meta Field not Working with qTranslate [closed]
- Problem in custom meta boxes
- Loop through two different sets of custom fields
- Metabox with multiple fields added by user and upload box
- Get all meta keys assigned to a post type
- Move value from one meta key to another
- How to associate 2 custom fields together (date & price for instance)?
- Is it possible to create a post from an NextGen Gallery image?
- Add first url to custom field on publish_post
- Use meta_query to get title of associated post
- Limits, not all post are showen when querying for posts by view count
- How to make custom fields respect paragraph breaks
- modify wordpress custom field value – strip character if exists
- Conditional operator OR not working with custom fields
- Sort posts by clicks on download button
- Posts query according to meta box date
- create metabox to activate slider
- MetaBox not saving after empty
- Show Custom Field of Current Page in For Loop
- Custom Field & Gravity Forms [closed]
- Redirect DRAFT Posts to a Custom URL (Custom Field) : Currently 404 Page
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- Trouble with serialized metadata
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- want to add video upload option for front end user
- Saving and using Custom Field in user settings/profile “Checkbox list”
- Override edit_custom_walker.php to conditionally show input depending on menu position
- Change event firing in wordpress
- Use custom field value as href
- WP_Query sort by ACF date field (newest first) with blank dates first