
While you can select draft posts in the admin they should not appear on the front end, usually, it can happen if you return post IDs.
ACF has a filter that can be used to modify the values that can be selected in the admin, acf/fields/relationship/query

Try
$post_id = 0;
$object = get_queried_object();
if (is_a($object, 'WP_Post')) {
$post_id = $object->ID;
}
the_field('header_code', $post_id);
I’d want to utilize ACF to produce unique data in the head> and footer for each page.
When a new post is created doing the sync, what happens?
First round is that it creates a draft, which is normal for the plugin.
When an existing post is updated and fields that did not have values are populated, what happens?
I can see the new text when viewing the post in the back end, but it does not become visible on the front-end until manually clicking publish.
When an existing post is updated and fields that did not have values are populated, what happens?
Same as above.
What type of fields are they?
Text and text area. Not sub-fields.
Just did another test… a post listed as being published:
https://sanktoberholz.de/wp-content/uploads/2021/09/Screen-Shot-2021-09-06-at-4.24.39-PM.png
And yet isn’t visible via post query until I hit Update again. Here’s the post query that I’m using, which shows a meta query for displaying only those that have been marked as a specific category (in Salesforce, not a WP category) and a checkbox for whether to make the post visible. (Its for a rudimentary inventory management process.)
<?php
$args = array( 'posts_per_page' => -1, 'post_type' => 'assets',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'area',
'value' => '["MITTE"]',
'compare' => '='
),
array(
'key' => 'show_on_website',
'value' => 1,
'compare' => '='
)
)
);
$myposts = get_posts( $args );
if($myposts):
foreach ( $myposts as $post ) : setup_postdata( $post );
?>
Adding that I want to use ACF to output unique values for each page in the <head> and footer.

See the section on this page about Dynamic $_GET parameters
This is the direction I would go in. This would allow altering the existing archive page to only show pages where the alternate language field has a value
meta_key => your field key
meta_value => ”
meta_compare => ‘!=’

I do not know how your site was built. I’m guessing that the developer used flexible content fields for the “components”. If the theme templates do not already add id attributes to the HTML then you would need to alter the templates to add this and quite possibly add some type of field to each of the flexible content layouts to allow entering or allowing unique ID values for each layout.
Thanks for tip!
I also found the following resource quite helpful: https://www.advancedcustomfields.com/resources/acf_add_options_page/
Hi @james
Could you please tell me how, in your previous example, I can add the following code, in order for me to create a new post ?
'new_post' => array(
'post_type' => 'questionnaire_ws',
'post_status' => 'publish',
'post_title' => 'lorem test',
),
My goal is to create a post type “questionnaire_ws” with multiple acf groups 🙂
Anchor IS indirectly mentioned in the documentation: the documentation states:
supports
(Array) (Optional) An array of features to support. All properties from the JavaScript block supports documentation may be used. The following options are supported:
If you read the linked documentation at https://developer.wordpress.org/block-editor/developers/block-api/block-supports/ — anchor is the first parameter on the list.
Ok, ok, in classic form you know how after a couple of hours of banging your head and then posting in support as a final cry for help you stumble across the obvious answer.
Well, here it is in case anyone else is lost.
You need to make sure “SUB” is added to the code like so:
<?php if( get_sub_field('file') ): ?>
<a href="<?php the_sub_field('file'); ?>" >Download File</a>
<?php endif; ?>
So add “get_sub_field” and “the_sub_field” and it will work. You need to add “sub” for repeaters and adjust the code inside accordingly.
In your first example you are using the category__in argument which can only be used with the category taxonomy.
In WooCommerce the product category taxonomy is a custom taxonomy. Since it is a custom taxonomy instead of using category__in in your second example you should use a tax_query. Take a look at the tax_query documentation for wp_query, it is pretty intuitive to set up if you are not familiar with it.
Hope this is helpful!
Since you are using global $post one thing that occurred to me is if there are any custom queries on the page make sure that wp_reset_postdata() is called. It could be that somewhere in your template the global $post variable is being reassigned without being reset.
Not sure if this is relevant but hope this is helpful!

Hey @kandb,
Yeh – so it’s specifically that double wrapper that’s our main issue at the moment. We don’t get much control on the outer wrapper, that’s a WordPress default and our attempts to avoid applying those classes/styles there have caused issues. The inner “wrapper” comes from your template, and that’s where these styles should live – but because we need to render PHP to build your template, we can’t easily “live” update your template with the styles as you do something in the block editor, say adding padding etc.
Also, of course – someone could decide to put the styles somewhere deeper into the DOM of their template, so we can’t also just rely on the “outer” wrapper being the place where that should live. If we do stop the styles being applied on the WordPress outer wrapper, you’d have to wait for the AJAX request to re-render the template to see your changes, and this feels incredibly slow and “broken” vs native blocks.
Anyway! We’ll get the fix for specific issue of the editor “forgetting” when you’ve applied things like spacing in the next day or so, and figure out the way forward from there!
Hi,
I also have the same problem with images in ACF blocks. Width & height restrictions from ACF image fields are being applied to the Core image block, if I add a core image block to the page after the ACF block.
If I:
I have tested this quite a bit:
I have been unable to solve this.
Environment:
Hmm.. the same problem here and only for one specific site. @buddyq Did you solve the problem?
I had a similar issue where i needed to add the ACF fields meta_id. Below is my solution to the same problem
function build_meta_key($field){
// Loop over parents.
$return_name = $field["_name"];
if(empty($field["prefix"])){
return $return_name;
}
$is_row = preg_match("/row-(\d)+/", $field["prefix"], $matches);
if(!$is_row){
return $return_name;
}
//now figure out the row number from the field name
$return_name = $matches[1]."_".$return_name;
while ( $field['parent'] && $field = acf_get_field( $field['parent'] ) ) {
if(isset($field["_name"])){
$return_name = $field["_name"]."_".$return_name;
}
}
return $return_name;
}
function get_all_meta_info_by_key($post_id, $meta_key, $meta_type = "post"){
global $wpdb;
if ( ! $meta_type || ! $post_id || trim($meta_key) == "") {
return false;
}
$table = _get_meta_table( $meta_type );
if ( ! $table ) {
return false;
}
$meta = $wpdb->get_row( $wpdb->prepare("SELECT * FROM {$table} WHERE post_id = %d AND meta_key = %s", $post_id, $meta_key) );
if ( empty( $meta ) ) {
return false;
}
if ( isset( $meta->meta_value ) ) {
$meta->meta_value = maybe_unserialize( $meta->meta_value );
}
return $meta;
}
/**
* Add in the ACF fields meta id to the field itself. so we can build the download links
* @param $field
*
* @return mixed
*/
function prepare_field( $field ) {
global $post;
$acf_meta_key = $this->build_meta_key($field);
$meta_information = $this->get_all_meta_info_by_key($post->ID, $acf_meta_key);
if(!empty($meta_information->meta_id)){
$field["post_meta_id"] = $meta_information->meta_id;
}
return $field;
}
Hey ACF/Elementor Friends 🙂
Here are some snippets that are working on my client’s site:
PHONE MAILTO
// Convert Mobile to tel link
add_filter('acf/format_value/name=ACF_MOBILE_FIELD_NAME', 'convert_phone_to_link', 20, 3);
function convert_phone_to_link ($value, $post_id, $field) {
if (!$value) {
return $value;
}
$tel_link = preg_replace('/[^0-9]/', '', $value);
$value = '<a href="tel:'.$tel_link.'">'.$value.'</a>';
return $value;
}
EMAIL MAILTO
// Convert Email to mailto link
add_filter('acf/format_value/name=ACF_EMAIL_FIELD_NAME', 'convert_email_to_link', 20, 3);
function convert_email_to_link ($value, $post_id, $field) {
if (!$value) {
return $value;
}
$email_link = $value;
$value = '<a href="mailto:'. $email_link .'">'. $value .'</a>';
return $value;
}
Done!
I’m sort of “wait and see” on the ownership change, but I can certainly see the advantages of having more resources available. I’ve seen some neat feature requests not happen probably more due to limited time/talent than anything else.
Would like to see them hire you, John, if that’s ever an option. 🙂
Ok, I don’t know why, but it’s working as expected now.
It must have been a cache issue, but I swear I was clearing the cache regularly.
For the sake of closure, here’s the code that worked (once the field was accessible):
<section class="center-align stories" id="stories">
<div class="wrap cf">
<div class="row">
<?php
if (have_posts()) : while (have_posts()) : the_post();
$my_id = get_the_ID();
?>
<?php // Only show posts where 'visibile_on_index' is not 0 (either 1 or unset)
if (get_post_field('visible_on_index', $my_id) != 0) { ?>
<div class="fourth <?php foreach(get_the_category() as $cat){ echo ' '.$cat->slug; }?>">
<div class="inner">
<a href="<?php the_permalink(); ?>" class="img-holder" style="background-image: url(<?php the_post_thumbnail_url('full'); ?>)"></a>
<a href="<?php the_permalink(); ?>">
<h4><?php the_title(); ?></h4>
</a>
<?php the_excerpt(); ?>
</div>
</div>
<?php }; ?>
<?php endwhile; ?>
<?php bones_page_navi(); ?>
<?php endif; ?>
</div>
</div>
</section>
Have you added the field afterwards?
No, field was added before I started trying to use it on the archive page.
Have you re-saved the posts then?
Yes, I can see the field on the Admin side when I edit a post (and on the index view since I’m also using the ACF QuickEdit fields plugin).
Are the other fields coming from a different field group or are they in the same group?
They are in a different group. I tried creating the field in a group that *does* appear using get_fields(), but no change. I checked settings between this group (that doesn’t appear) and a group that does appear and all settings are the same.
In ACF Pro v5.9 or more, you can do :
function your_function_name($field) {
return false;
}
add_filter("acf/prepare_field/name=my_acf_field", "your_function_name");

I’m not quite understanding the problem here. First you say:
If I call the field in the custom section I get a result (15), so I know the field has a value.
And then you say:
I can give the shortcode a parameter for ID, but in that custom section, I can’t get the actual ID to put it in the shortcode.
Also, what do you get if you do var_dump($id_i_need)?

You can change field labels but not field names (slugs) without losing the connection to previously entered data.
For example, if you have a text field with label “Camera Lens 1” and field name “camera_lens_1” you can change the label and the new label text will be shown in the templates where this label is used. But if you change the field name it will not update the old data in the database, so you would start with an empty list again. The old data isn’t lost, it’s still in the database, but it won’t be accessible unless you change the name back to the old one.
I hope I’ve understood your question correctly. For more specific answers you’ll have to post your field setup exactly.
Thanks for reply.
but it looks doesn’t work. even i hard code the post id.
<?php echo get_field('students_no_class', get_queried_object() , 456 ) ?>
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.