@hube2 I am still not clear – do i put the code in the template php file for the posts that have the fields whose values i am putting into the message field? And are we talking about the message field displaying its values on the front end or the back end? Backend is the goal.
I added a message field – and it doesn’t have a name field, only label, so i named the label MESSAGE_FIELD_NAME and this field is on the same posts as the fields it’s supposed to be showing. When the post is saved and the page refreshes, that’s when i’m hoping to see the message field’s value, but there’s nothing.
For some reason this hasn’t clicked for me yet. Can you help me more?
Here is a tutorial for adding custom fields to a WooCommerce product and displaying them on the products template:
https://themeisle.com/blog/custom-fields-woocommerce/
Another option for displaying the values from your ACF fields on the products template outside of using the short codes which the above tutorial does not get into is WooCommerce provides a number of hooks/filters that can be used with the single products template to add information/customize the output. These hooks/filters can be placed in the functions file of your theme to output the additional ACF fields you want to include on the products template.
Hope this is helpful!
Thanks again John. What really annoys me is the developers have created this fantastic plugin, then gone further and added a javascript library which adds another level of sophistication, but then seem to ignore customers that want to make use of it.
I’ve worked for 40+ yeas in IT development. support and consulting, and I understand it’s difficult, but we never released a toolset then didn’t give our customers documentation or support for it.
Anyway, enough a a rant. I have a field group as follows;
Picture – image
Location – text
Date – datepicker
People – Repeater
–Person – relationship
–coord_left – number
–coordtop – number
–coordright – number
–coordbottom – number
I load the image and run a js using Clarifai’s face recognition engine. It returns boxes around each face in the picture and a list of coords of these boxes.
I want to populate the repeater field with the ID of a unknown person (from the people field group) and he coords from above. The user will then change the person from the unknown person to one from the field group and save the post.
I have the recognition working and the trigger click firing the code from the acf.addaction append code you pointed me at. I’m trying now to add the ID and coord fields with the data from the face recognition.
I was hoping I could have something to loop through the faces I have, triggering the new row, then adding the 5 fields. Although this should work, it’s a bit messy.
I would have hoped there was a add.row function that I could call to add my rows before displaying them, rather than acting like keyboard input and relying on the users to save the updates.
I find it very difficult to identify the field names as on the page they seem to be part of a hierarchy which I cannot find a description for (e.g. id=”acf-field_609af70f9fdac-acfcloneindex-field_609af86f9fdb1″ name=”acf[field_609af70f9fdac][acfcloneindex][field_609af86f9fdb1] where the field ending in db1 corresponds to one of the coordinate fields I defined). This makes the coding more difficult.
I hope I’ve not gone on too much, but thanks for your help anyway.
row
#

It’s not that I’m apposed to sharing, not really anything super secret, but the scope of what I have is too huge to share on a forum.
In order to get pagination to work correctly you need to use a pre_get_posts filter on on the archive. Or at least that is the easiest way for me to do it. I suppose that you can do it with get_posts(), but it would be more difficult. When you modify the main query then you can use built in WP functions for the pagination links.
For example, here is my pagination code on one site that uses a simple previous/next link, I use my own function because I wrap the links in bootstrap columns.
function events_nav_links() {
if (!get_previous_posts_link() && !get_next_posts_link()) {
return;
}
?>
<div class="row events-archive-nav" style="margin-bottom: 2em;">
<div class="col-6 text-left previous">
<?php previous_posts_link("« Earlier Events"); ?>
</div>
<div class="col-6 text-right next">
<?php next_posts_link("Later Events »"); ?>
</div>
</div>
<?php
}
This one uses pagination links to show page numbers
// maybe page links
$current_page = max(1, get_query_var('paged'));
$args = array(
'base' => get_pagenum_link(1).'%_%',
'format' => 'page/%#%/',
'prev_text' => '<i class="fal fa-chevron-left"></i>',
'next_text' => '<i class="fal fa-chevron-right"></i>',
'current' => $current_page,
'mid_size' => 5,
'type' => 'array'
);
$page_links = paginate_links($args);
if (!empty($page_links)) {
?>
<div class="row">
<div class="col-12 event-page-links number-page-links">
<div class="row justify-content-center">
<?php
foreach ($page_links as $link) {
//$link = str_replace('//', '/', $link);
$extra_classes = array();
if (preg_match('/(prev|next)/', $link)) {
$extra_classes[] = 'icon';
} elseif (preg_match('/current/', $link)) {
$extra_classes[] = 'current';
} else {
$extra_classes[] = 'page';
}
$class = '';
if (!empty($extra_classes)) {
$class = ' '.implode(' ', $extra_classes);
}
?>
<div class="col-auto link<?php echo $class; ?>">
<?php echo $link; ?>
</div>
<?php
}
?>
</div>
</div>
</div>
<?php
} // end if page links
Like I said, I don’t know if it’s possible to do something similar using get_posts() in the template, but it will be more difficult. I try to always use built in WP functions when I can and using WP’s built in pagination functions are easier than trying to build something yourself. Altering the main query through a pre_get_posts_filter is just easier.
the following is a pre_get_psots filter from a site that only shows current and future events in the archive
function events_archive_only_children($query) {
if (is_admin() || !$query->is_main_query()) {
return;
}
// tests to make sure that we are displaying an event page
if (!isset($query->query_vars) ||
!isset($query->query_vars['post_type']) ||
$query->query_vars['post_type'] != $this->post_type) {
// test for event-category tax
if (!isset($query->query_vars) ||
!isset($query->query_vars['event-category'])) {
// test for event-tag tax
if (!isset($query->query_vars) ||
!isset($query->query_vars['event-tag'])) {
// test for event-type
if (!isset($query->query_vars) ||
!isset($query->query_vars['event-type'])) {
// text for event-visitor-type
if (!isset($query->query_vars) ||
!isset($query->query_vars['event-visitor-type'])) {
// not of the possible query vars for events is set
return;
}
}
}
}
}
// double check we are not on a single page
if (is_single()) {
return;
}
// custom query parameters (custom search form) that might be set
// if visitor's browser does not support JS
// redirect to correct URL based on event rewrite rules
// custom taxonomies include event type and visitor type
$type = false;
$visitor = false;
if (isset($_GET['e-type']) && !empty($_GET['e-type'])) {
$type = $_GET['e-type'];
}
if (isset($_GET['e-visitor']) && !empty($_GET['e-visitor'])) {
$visitor = $_GET['e-visitor'];
}
if ($type || $visitor) {
$url = '/event/';
if ($type) {
$url .= 'type/'.$type.'/';
}
if ($visitor) {
$url .= 'visitor/'.$visitor.'/';
}
wp_redirect($url, 301);
exit;
}
// posts_per_page
// setting on options page allows client to set
if (function_exists('get_field')) {
$post_id = $this->options_page;
$posts_per_page = get_field('events_per_page', 'events_options');
if ($posts_per_page === 0) {
$posts_per_page = -1;
}
$query->set('posts_per_page', $posts_per_page);
}
// this framework uses parent/child events
// to allow multiple event start and and dates
// and recurring events
// only show child events on the admin
$query->set('post_parent__not_in', array('0'));
if (isset($query->query['year'])) {
// doing a date query
// The following converts standard WP date searches
// into a meta query on start & end dates ACF date/time fields
// and removes the WP date query
// shows any event starting in the selected year/month/day
$date = $query->query['year'].'-';
unset($query->query['year']);
$query->query_vars['year'] = '';
if (isset($query->query['monthnum'])) {
$date .= $query->query['monthnum'].'-';
unset($query->query['monthnum']);
$query->query_vars['monthnum'] = '';
};
if (isset($query->query['day'])) {
$date .= $query->query['day'];
unset($query->query['day']);
$query->query_vars['day'] = '';
};
$meta_query = array(
'relation' => 'AND',
'start_date_clause' => array(
'key' => 'start_date',
'value' => $date,
'compare' => 'LIKE',
),
'end_date_clause' => array(
'key' => 'end_date',
'value' => date('Y-m-d H:i:s'),
'compare' => '>',
'type' => 'DATETIME'
)
);
} else {
// not doing a date query
// add standard meta query to only show current or upcoming events
$meta_query = array(
'relation' => 'AND',
'start_date_clause' => array(
'key' => 'start_date',
'compare' => 'EXISTS',
),
'end_date_clause' => array(
'key' => 'end_date',
'value' => date('Y-m-d H:i:s'),
'compare' => '>',
'type' => 'DATETIME'
)
);
}
$query->set('meta_query', $meta_query);
// order by start/end date acf fields
$order = array(
'start_date_clause' => 'ASC',
'end_date_clause' => 'ASC',
'title' => 'ASC'
);
$query->set('orderby', $order);
}
Hey John, sorry for bringing this up again, but since I was having a hard time explaining the issue, I decided to just poke around until I figured it out but I’m still having problems.
I think a simpler explanation is that the default way of displaying my posts in the relationship field is like this:
Bios
Jack Brown
Jane Smith
John Doe
Resumes
Jack Johnson
James Thompson
But I need the results to simply display like this:
Jack Brown
Jack Johnson
Jane Smith
James Thompson
John Doe
So no grouping by post type. I’ve poked around in the code and the get_ajax_query function calls the function acf_get_grouped_posts which groups the results by post type, and as far as I can see there’s no way to bypass the grouping function. So I’m thinking I need to create a custom ACF Relationship field/plugin that doesn’t call the acf_get_grouped_posts. I just want to check in real quick and see if I’m missing something before doing that, since it’s not an ideal solution.
Thanks you!

This is only a back end mechanism for field layout purposes, similar to a tab field, and it cannot be used for displaying content on the front of the site.

I don’t know how you can do this.
An ACF image field only stores the image ID and there isn’t any way to have ACF store additional data for the image.
Possible solution:
1) Store the generated value in a hidden field
2) Create an acf/save_post filter that gets the hidden value and makes any needed changes to the attachment post for the image or its meta values that you’ll need for displaying this image. Maybe you need to somehow insert the image into the media library and alter the image ID stored by ACF. I am not familiar with how you can do this with the data that will be provided. You might potentially start here https://rudrastyh.com/wordpress/how-to-add-images-to-media-library-from-uploaded-files-programmatically.html
Hi @elliot, this solution didn’t work in my situation, unfortunately.
<?PHP
$content = get_field('wysiwyg', false, false);
echo apply_filters('the_content', $content);
?>
It destroys the output of the wysiwyg, displaying nothing.
I have the plugin Simple Lightbox installed, which I want to use for the gallery’s lightbox.
Previously, I was using:
<?PHP
the_sub_field('wysiwyg');
?>
To output the wysiwyg normally.
Help appreciated.
Steve

If you want to remove them from one page on the front end then you need to alter the code of the template that is displaying the fields, detect what page it is and add a conditional so that they are not shown.
The reason why I posted this originally was because It seems unnecessary to load on the front end for example date picker and timepicker javascript files if the front end is only displaying a text input.
I think the last comment just posted might be echoing this – there is a way to conditionally include scripts on the front end based on what fields are actually being used.
Anyway, I’m not anymore concerned with this but thought I would offer my reasoning. Cheers!
Hi! Sorry to revive this old thread, but I found this searching for an option to deactivate certain fields on the frontend. Right now, I’m able to dequeue the CSS and JS manually and that’s okay for most of my fields, but I also have some fields that echo some content (namely SVG icons that are hidden with display:none) to facilitate rendering them on the backend when they’re needed.
That also comes from the fact that I have a few custom fields plugins enabled on the website I’m working on and I’d like to selectively stop them to be “activated” at all on the frontend. All of the fields are always enqueueing their settings and assets regardless if they’re used or not in the form I’m actively displaying on the frontend. In that example, my SVG Icon selector enqueues it’s CSS, JS and echoes its icons even if there’s no SVG Icon selector field added in the form itself.
Seems like there should be a filter to shortcircuit a field altogether in that case but I can’t find it right now, but that brings me to the other question: aren’t fields lazily initialized? Should they not or is it too complicated since it doesn’t really matter for the backend of things?

get_fields() can be used to get all of the field values and then loop over them.
However, this is not generally usable when fields in a group are changed or if the fields associated with a post can change when updated. The reason for this is that ACF calls get_post_meta() with a post ID and no meta_key. This causes WP to return all of the custom fields for the post. But these fields are returned in the order that they were added to the database ordered by “meta_id”. This means that fields added later will appear later in the returned array and the returned array will not be in the order that the fields appear in the field group, or for that matter, on the post.
So let’s say that you have 2 fields, “text 1” and “text 2” and they originally appear in this order. When a post is initially created they are saved in this order. If you later change this order in the field group then get_fields() will still return them in this order for older posts while it will return the fields in the new order for posts created after the change was made.
So, get_fields() is only useful if you don’t care what order the fields are displayed in.
An alternative would be to call $field_groups = acf_get_field_groups(array('post_id' => $post->ID));. This will return a list of all of the field groups for the post. Then you’d need to loop over the fields in the field groups and then you could possible create some type of dynamic display based on the field type of each of these fields and make it recursive for repeater type fields. This would be a very big task given the possibilities available in ACF. While this is possible, it’s far easier and faster to edit a template to add field display in the order that you want them to be shown.
I’ve never found any type of dynamic solution for displaying fields because I do not build the admin pages for my clients with the fields in the order I want them displayed. I break up fields using tabs and other features to break up the fields into groups based on what they are for to make is easy for entering data.
however text fields are displaying in post page but not in front page!
Update II: In response to the issue of my thumbnails not displaying; I have figured this out if anyone else with similar issues stumbles into this…
Basically, for me, I eliminated the then unnecessary pre_get_posts filter and then replaced;
<?php $image = wp_get_attachment_image_src(get_field('event_thumbnail'), 'full'); ?>
<img src="<?php echo get_field('event_thumbnail'); ?>" alt="<?php echo get_the_title(get_field('event_thumbnail')) ?>" />
with:
<?php $image = get_field('event_thumbnail'); ?>
<img src="<?php echo $image; ?>" alt="<?php echo get_the_title(get_field('event_thumbnail')) ?>" />
For some reason (probably some conflict again), wp_get_attachment_image_src returns as false. But get_field('event_thumbnail') returns the image anyway, so all that was needed was to remove this wp_get_attachment_image_src function!
Hope this helps someone!
I see…!
Thank you for your patience!!
It’s very unfortunate though that ACF has not evolved to broaden its usage for front-end displaying too!
On the other hand, thank God we have tools such as elementor and dynamic fields to help us most of the way with this.
I will try and implement your code in my functions.php and see if I can make it work that way. I will back-up, then back-up and back-up my installation before I proceed and see if I can work it out 🙂
I can understand some pieces of your code, but I couldn’t come up with it myself…!
Thank you again!!!

The reason is that ACF does not include conditions for showing fields on the front end and this requires coding, for example
// get terms associated with post
$terms = wp_get_post_terms($post->ID, 'your-taxonomy');
// see if there are terms
if ($terms) {
// loop over terms
foreach ($terms as $term) {
// test to see if this is a term with custom field to show
if ($term->name == 'special term') {
// get the value of the field from the term
$term_field = get_field('field_name', $term);
}
}
}
I cannot tell you how to do this is a tool designed to build output in the admin and more than likely no one that visits this forum will be able to help you with this. Most of the people that use ACF code templates using PHP. ACF is an admin tool that helps you create fields and does not include automated code for displaying the values on the front of the site.

First I am going to repeat my comment from your other topic the if statements here are not effective and the code inside of them will run whether or not get_field() returns any results.
Second issue is that you are now taking about repeaters that are completely different than a gallery field.
When you use get_field(‘repeater’) and you get a string back, the issue is that ACF is returning the actual value of the repeater from the database and this value is the number of rows contained in the repeater. When this happens it is due to a conflict with some other code on the site and this is usually cause by a “pre_get_post” filter that is interfering with ACF getting values. Since this is an options page it could also be any filter in WP getting options.
The first thing that you need to do is figure out where this conflict is. You need to test by deactivating other plugins and possibly switching themes to narrow down the cause. Once the cause is narrowed to the theme or a specific plugin it will be easier to figure out.
The choice value *should* be blue with a lower case, based on the custom filter loading the in the dynamic choices. That’s been the problem. The choices for the field are displaying the original field values and not the values being created from the filter.
I’ve replicated this on a second site, simply hitting “update” on the field group assigned to that block type resolves my issue with the ACF block not displaying in the editor.
Sorry for the late answer, I tried to do what you said, I created a new file (acf.php) and uploaded it but when I try to change the page template it didn’t even show up.
This is the code of acf.php
<?php
/*
Template Name: Page with custom fields
Template Post Type: ACF
*/
get_header();
the_content();
if (get_field('proprietario')) {
?>
<strong>PROPRIETARIO:</strong> <?php the_field('proprietario'); ?><br />
<?php
}
if (get_field('indirizzo')) {
?>
<strong>INDIRIZZO:</strong> <?php the_field('indirizzo'); ?><br />
?>
<?php
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package Patus
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'page' ); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

The developer did not prevent you from creating new layouts. Each new layout must have corresponding code in your theme to display that layout.
Somewhere in the code of the theme there will be a call to the function get_row_layout(). This call returns the layout name of the current layout in the flex field. This code will be followed by code created specifically for displaying the fields based on the layout name returned.
Different developers do this in different ways, but without adding the code for the layout the layout will just be ignored because the code does not know what to do with it.

the code
$value = apply_filters( "acf/update_value", $value, $post_id, $field, $value );
is called before any filters are applied. At this point the original value will always be the same as the current value.
Filters can only modify the $valueand cannot alter the$orig_value` (argument #4). Every filter may get a different value but they will always get the same original value.
Testing this with multiple filters set at different priories and displaying both the current value and the original value in each one I get a constantly changing $value while $orig_value (argument #4 to my filters) remains unchanged.
I don’t understand how is this working in a way that’s unexpected?
That makes sense! Thanks John.
I’m now wondering if I were to select a draft post when I retrieve the field on the front end will that draft post be included? The main thing that I would worry about is accidentally displaying draft posts on the front end that should not be public
Going to test this today
Thanks again for your help John. Unfortunately, that’s not a variable. I have several boxes and I need them to know to stop displaying as of ‘Today’ or ‘Tomorrow’ or whatever. I don’t want to put a specific date in the conditional field.
A thought about ACF and Gutenberg:
Site creators and editors (not specifically developers) are using ACF for creating backend fields. I often see questions about the last step in the process – either setting up the php template or creating a block for displaying the ACF content in the front end. Which brought me to the thought of a multi-use/dynamic ACF GB block that can display the content of the ACF fields in the front end without the need for coding a GB block or a PHP template.
This would be a native ACF block, bundled as part of the plugin. The user, after creating the ACF fields in the ACF admin would then populate the content in the editor screen and then open up the ACF GB block from withing the block editor, select from a dropdown the field he wants to display and that’s it – the content would be shown on the page. No need to create a php template or a custom block. One block can display any ACF created content.
For each element in the ACF GB block there will be the core GB controls (color, size, alignment etc…). These are pretty raw thoughts, I’m sure they can be improved.
Does this make sense? Has this been created already?
Here is a sketched flow of the process.
Image here:
https://imgur.com/4gGh5ro
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.