Are you using bi-directional relationships? (there’s a checkbox on the relationship field)
Custom fields are stored as meta data in a separate table which are separate to post data and that’s why you don’t get it with wp_query.
By default, WP_Query returns the standard WP_Post objects for the posts being queried. I believe with some clever rewrite and use of the filters given in WP_Query you can add objects to the returned WP_Post objects array.
In my opinion, it will hurt performance more as you will need to join results in your query as custom fields are not saved in the wp_posts table, but in the wp_postmeta table.
You can loop through the posts and attach the required meta data yourself. with $posts->posts; in your example
Retrieving post meta is really fast and it does not require any extra instance of WP_Query. You can simply call the custom field with get_post_meta(). WordPress was very thoughtful when the custom fields was introduced. They added a cache to cache them, so whether you are querying 1 or 100 custom fields, you are hitting the database once, superfast.
In my opinion, the extra database call and the actual time spent is worth it and faster than rewriting WP_Query in such a way to include custom fields in the standard post object returned by $posts.
HTH
You could do that as long as it doesn’t conflict with an existing property but it will only last for the lifecycle of the object i.e it won’t be saved to the db and be available to use when the page loads.
What additional information do you want to add to the field?
I use the technique in the link and it’s still working here. Maybe post a code snippet
You can use the oembed field for youtube videos
the field variable being passed contains ‘toolbar’ ie field[‘toolbar’] – you need to check that for the name you gave the simple version (there is ‘basic’ built in) and then do your logic
You can target the field type:
acf.addAction('load_field/type=wysiwyg', function(field) {
///.. the code from above
})
You can do this to heck the URL value. There are few different ways for the user to enter a URL so they all need to be covered
acf.addAction('load_field/key={the key of your oembed field}', function(field) {
$(field.$el).on("change", "input[type=text]", function(e){
let val = $(this).val();
// pass val to your validation method
});
$(field.$el).on("click", "input[type=text]", function(e){
let val = $(this).val();
// pass val to your validation method
})
$(field.$el).on("keyup", "input[type=text]", function(e){
let val = $(this).val();
// pass val to your validation method
})
})
Anyone struggling with the above query from @extrasmall the working syntax should be (a couple of quote marks missing on the str_replace statement)
function allow_wildcards( $where ) {
global $wpdb;
$where = str_replace(
"meta_key = '{$repeater_field_name}_%_{$sub_field_name}'",
"meta_key LIKE '{$repeater_field_name}_%_{$sub_field_name}'",
$wpdb->remove_placeholder_escape($where)
);
return $where;
}
add_filter('posts_where', 'allow_wildcards');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.