@nicmare in the last 2 days i’ve tried getting caught up on where things stand with query block custom field shortcode status, found this post, and your solution cleared things up for me on this. thanks.
I haven’t though of using a repeater so I’ll look into that. I have one last question. If I need to update an existing value in the field how do I go about it? Let’s say I have 5 different jsons in the field and I need to update the second one.
You may want to consider only adding that filter for when the results of that field. To do that use https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/ and put add_filter( 'posts_search', '__search_by_title_only', 500, 2 );
in that filter. Then it will only be used on that search rather than all searches on the site.
That is the same issue, you need 4 values, not 3.
So try this:
$image = get_field('quick_ship');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size, "", array ('class' => 'quick-ship' ) );
}
Finally, I resolved it like this, on the second query inside the loop
<?php $negatives = get_field( "collections_single_work"); ?>
<?php if( $negatives ): ?>
<?php foreach( $negatives as $post ): ?>
<?php setup_postdata($post); ?>
here goes some coding
<?php $related_posts = get_field('collection_edition_size');
if ($related_posts) {
foreach ($related_posts as $related_post) {
?>
<?php if( get_field('size_of_the_negative', $related_post->ID) == '4x5'): ?>
here goes some coding
<?php
}
} ?>
here goes some coding which is part of the first loop
<?php wp_reset_postdata(); endforeach; ?>
<?php endif; ?>
@hube2 , hi trying to do this to apply a class to woocommerce single product gallery thumbnails. i’m using a true/false acf field on media attachment.
this code is not working for me:
<?php
$image = get_field('quick_ship');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size, array ('class' => 'quick-ship' ) );
}
Yes, one requirement is editable fields which is why acf was chosen to host the data.
To pick up on this thread, I have the Gallery field working fine IF you’re logged in, but it’s not working for logged-out users.
I’ve tried putting the uploader function in my code like this, but still not working:
add_action( ‘genesis_entry_content’, ‘shs_new_content’ );
function shs_new_content() {
acf_enqueue_uploader();
acf_form(array(
‘post_id’ => ‘new_post’,
‘post_title’ => true,
There is nothing that connects the field values saved with the field group. The only attachment is to the post, term or user that the metadata is for.
This topic has come up many times [Forum Search]
Actually, I don’t worry about the extra data because under normal operation it should not affect performance. Both the post_id and meta_name columns on the database tables are indexed. Since most queries are base on these columns the extra rows have little to no affect on query performance.
Site performance is affected more by the number of queries performed or by performing “LIKE” queries on columns that are not indexed. Any queries based on the meta_value column would also be significantly affected, but this would still be the case without the extra rows. However, even here, when searching the meta_value you would likely still include the meta_key in your query, which is an indexed field, therefor an unused meta_key row would already be ignored by such a query and therefor that row would have no impact on the query.
When talking about even a couple of dozen extra fields or more returned when doing a single query to get all of the metadata for a post, term or user the extra data returned has little affect on the individual query. You would need to have several hundred extra fields being returned to significantly impact the response time of a query.
This is not friendly or completely safe way to delete unused fields.
You would have to run a delete query directly on the DB for each field and this would be unsafe unless the field name is unique.
Man, still a no-go. Here’s what I have now:
$args = array(
'fields' => 'ids',
'posts_per_page' => 1,
'post_type' => 'post',
'post_status' => 'any',
'meta_query' => array(
array(
'key' => 'image_meta_image_id',
'value' => $image_meta_image_id
)
)
);
$attachment_query = new WP_Query( $args );
$attachments = $attachment_query->posts();
var_dump( $attachments ); gets me bool(false), but I see it in PMA (attached).
var_dump( $attachment_query ) is below.
Appreciate any other ideas you might have. Thanks so much!
object(WP_Query)#3567 (52) {
["query"]=>
array(5) {
["fields"]=>
string(3) "ids"
["posts_per_page"]=>
int(1)
["post_type"]=>
string(4) "post"
["post_status"]=>
string(3) "any"
["meta_query"]=>
array(1) {
[0]=>
array(2) {
["key"]=>
string(19) "image_meta_image_id"
["value"]=>
string(5) "16233"
}
}
}
["query_vars"]=>
array(67) {
["fields"]=>
string(3) "ids"
["posts_per_page"]=>
int(1)
["post_type"]=>
string(4) "post"
["post_status"]=>
string(3) "any"
["meta_query"]=>
array(1) {
[0]=>
array(2) {
["key"]=>
string(19) "image_meta_image_id"
["value"]=>
string(5) "16233"
}
}
["error"]=>
string(0) ""
["m"]=>
string(0) ""
["p"]=>
int(0)
["post_parent"]=>
string(0) ""
["subpost"]=>
string(0) ""
["subpost_id"]=>
string(0) ""
["attachment"]=>
string(0) ""
["attachment_id"]=>
int(0)
["name"]=>
string(0) ""
["pagename"]=>
string(0) ""
["page_id"]=>
int(0)
["second"]=>
string(0) ""
["minute"]=>
string(0) ""
["hour"]=>
string(0) ""
["day"]=>
int(0)
["monthnum"]=>
int(0)
["year"]=>
int(0)
["w"]=>
int(0)
["category_name"]=>
string(0) ""
["tag"]=>
string(0) ""
["cat"]=>
string(0) ""
["tag_id"]=>
string(0) ""
["author"]=>
string(0) ""
["author_name"]=>
string(0) ""
["feed"]=>
string(0) ""
["tb"]=>
string(0) ""
["paged"]=>
int(0)
["meta_key"]=>
string(0) ""
["meta_value"]=>
string(0) ""
["preview"]=>
string(0) ""
["s"]=>
string(0) ""
["sentence"]=>
string(0) ""
["title"]=>
string(0) ""
["menu_order"]=>
string(0) ""
["embed"]=>
string(0) ""
["category__in"]=>
array(0) {
}
["category__not_in"]=>
array(0) {
}
["category__and"]=>
array(0) {
}
["post__in"]=>
array(0) {
}
["post__not_in"]=>
array(0) {
}
["post_name__in"]=>
array(0) {
}
["tag__in"]=>
array(0) {
}
["tag__not_in"]=>
array(0) {
}
["tag__and"]=>
array(0) {
}
["tag_slug__in"]=>
array(0) {
}
["tag_slug__and"]=>
array(0) {
}
["post_parent__in"]=>
array(0) {
}
["post_parent__not_in"]=>
array(0) {
}
["author__in"]=>
array(0) {
}
["author__not_in"]=>
array(0) {
}
["search_columns"]=>
array(0) {
}
["ignore_sticky_posts"]=>
bool(false)
["suppress_filters"]=>
bool(false)
["cache_results"]=>
bool(true)
["update_post_term_cache"]=>
bool(true)
["update_menu_item_cache"]=>
bool(false)
["lazy_load_term_meta"]=>
bool(true)
["update_post_meta_cache"]=>
bool(true)
["nopaging"]=>
bool(false)
["comments_per_page"]=>
string(2) "50"
["no_found_rows"]=>
bool(false)
["order"]=>
string(4) "DESC"
}
["tax_query"]=>
object(WP_Tax_Query)#3974 (6) {
["queries"]=>
array(0) {
}
["relation"]=>
string(3) "AND"
["table_aliases":protected]=>
array(0) {
}
["queried_terms"]=>
array(0) {
}
["primary_table"]=>
string(8) "wp_posts"
["primary_id_column"]=>
string(2) "ID"
}
["meta_query"]=>
object(WP_Meta_Query)#3962 (9) {
["queries"]=>
array(2) {
[0]=>
array(2) {
["key"]=>
string(19) "image_meta_image_id"
["value"]=>
string(5) "16233"
}
["relation"]=>
string(2) "OR"
}
["relation"]=>
string(3) "AND"
["meta_table"]=>
string(11) "wp_postmeta"
["meta_id_column"]=>
string(7) "post_id"
["primary_table"]=>
string(8) "wp_posts"
["primary_id_column"]=>
string(2) "ID"
["table_aliases":protected]=>
array(1) {
[0]=>
string(11) "wp_postmeta"
}
["clauses":protected]=>
array(1) {
["wp_postmeta"]=>
array(6) {
["key"]=>
string(19) "image_meta_image_id"
["value"]=>
string(5) "16233"
["compare"]=>
string(1) "="
["compare_key"]=>
string(1) "="
["alias"]=>
string(11) "wp_postmeta"
["cast"]=>
string(4) "CHAR"
}
}
["has_or_relation":protected]=>
bool(false)
}
["date_query"]=>
bool(false)
["request"]=>
string(426) "
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
WHERE 1=1 AND (
( wp_postmeta.meta_key = 'image_meta_image_id' AND wp_postmeta.meta_value = '16233' )
) AND wp_posts.post_type = 'post' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 1
"
["posts"]=>
array(0) {
}
["post_count"]=>
int(0)
["current_post"]=>
int(-1)
["before_loop"]=>
bool(true)
["in_the_loop"]=>
bool(false)
["comment_count"]=>
int(0)
["current_comment"]=>
int(-1)
["found_posts"]=>
int(0)
["max_num_pages"]=>
int(0)
["max_num_comment_pages"]=>
int(0)
["is_single"]=>
bool(false)
["is_preview"]=>
bool(false)
["is_page"]=>
bool(false)
["is_archive"]=>
bool(false)
["is_date"]=>
bool(false)
["is_year"]=>
bool(false)
["is_month"]=>
bool(false)
["is_day"]=>
bool(false)
["is_time"]=>
bool(false)
["is_author"]=>
bool(false)
["is_category"]=>
bool(false)
["is_tag"]=>
bool(false)
["is_tax"]=>
bool(false)
["is_search"]=>
bool(false)
["is_feed"]=>
bool(false)
["is_comment_feed"]=>
bool(false)
["is_trackback"]=>
bool(false)
["is_home"]=>
bool(true)
["is_privacy_policy"]=>
bool(false)
["is_404"]=>
bool(false)
["is_embed"]=>
bool(false)
["is_paged"]=>
bool(false)
["is_admin"]=>
bool(false)
["is_attachment"]=>
bool(false)
["is_singular"]=>
bool(false)
["is_robots"]=>
bool(false)
["is_favicon"]=>
bool(false)
["is_posts_page"]=>
bool(false)
["is_post_type_archive"]=>
bool(false)
["query_vars_hash":"WP_Query":private]=>
string(32) "2ab9be15f5f96057950ea53522e2d60a"
["query_vars_changed":"WP_Query":private]=>
bool(false)
["thumbnails_cached"]=>
bool(false)
["allow_query_attachment_by_filename":protected]=>
bool(false)
["stopwords":"WP_Query":private]=>
NULL
["compat_fields":"WP_Query":private]=>
array(2) {
[0]=>
string(15) "query_vars_hash"
[1]=>
string(18) "query_vars_changed"
}
["compat_methods":"WP_Query":private]=>
array(2) {
[0]=>
string(16) "init_query_flags"
[1]=>
string(15) "parse_tax_query"
}
}
John, Thanks for your quick reply.
In this case, the parent and child theme field groups do not require further or ongoing editing. I understand how a parent and child theme relationship should work. Like I said I inherited this project so trying to clean things up. I am also finding evidence that the original developer might not have understood how to load all field group properly as their calls to some group options create errors in php 8 when returning null values. Anyway…
Currently the child theme and the parent theme share two files with the same group key. And what happens is that the parent theme json file gets used over the child file.
Would you recommend I rebuild the child fields and just redo all the data entry? or is there another “easier” method. Like, can I recreate a unique group key in the child theme and move forward from there?
This topic has come up many times here. A do not remember all of the specifics but there have been others that have solved this. You should take a look at some of those discussions.
[Forum Search Results]
Following on from above – field ‘voice_sponsored_article’ is a post object set to output post id. Modifying the query by hardcoding the post ID works as expected
function my_query_by_post_id( $query ) {
//$sponsored = get_field( 'voice_sponsored_article', 'voice_options' );//this doesn't work
$query->set( 'p', '186301' ); //this works
$query->set( 'p',$voicesponsored_link);// Nope
}
add_action( 'elementor/query/voicefilter4', 'my_query_by_post_id' );
but including the get_field line above seems to create an infinite loop.
Seems as though I need to build a meta query but unsure how to include the post id.
$meta_query[] = [
'key' => 'post_id',
'value' => get_field( 'voice_sponsored_article') //this is my intention
];
$query->set( 'meta_query', $meta_query );
This should be simple enough but I’ve yet to find an answer.
You are setting the post ID values of your options page ‘program-settings’ and ‘team-settings’
This means that when using ACF functions you must use these post ID value instead of “options”
the_field('programs_preamble', 'program-settings');
ACF uses the “post_id” as a prefix to the field name in the options table
"options_{$field_name}"
When you change the field name it changes the prefix
"program-settings_{$field_name}"
is the return value of your link field set to “Link Array”? This will be required.
Then set the priority of your filter to > 10 (for example 20)
I’m not sure I understand the question. A text field cannot hold an array. In fact, no ACF field can hold an array except those that are designed to do so. Relationship type fields, select and checkbox fields.
found your issue. You need to add
'post_status' => 'inherit'
to your query. The default status of a WP_Query() is “publish” but the default status for an attachment is “inherit”
You would have to remove the standard WP meta box for the taxonomy and create an ACF field to replace it in order to make selecting a term required.
Ah, I see. I have another question. If I want to load the field group such that a specific text is associated to a certain array, do I use the load value hook?
It doesn’t look like you are calling for the field group properly. Are you trying to access a repeater field? Your question needs more information.
This below custom query gives me a critical page error using an ACF post object set to post ID. I’m beginning to think Elementor queries using ACF are broken, at least with my WordPress install. I’ve ran troubleshooting mode and with all plugins active the Elementor editor page loads but only when this code is commented out.
add_action( 'elementor/query/voicesponsored_filter_2', function ( $query ) {
$voicesponsored_link = get_field( 'voice_sponsored_2', 'voice_options');
$query->set( 'p',$voicesponsored_link);
} );
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.