$grp = get_field('all_content');
$flex = $grp['flex_content'];
while(have_rows($grp)) {
if( have_rows($flex) ){
while ( have_rows($flex) ) {
the_row();
// Case: Paragraph layout.
if( get_row_layout() == 'content' ){
the_row();
echo get_sub_field('flex_content');
}
}
}
}
There isn’t any way that I’d attempt to move values on 2000 posts given my previous comment.
The best way to do this is to use the load_value hook on the new repeater. In your filter see if the the repeater has a value and remove the values in the old repeater using the same hook on that repeater.
Caution: Do actually update the database/fields. This way the changes are only made if the client actually save the post.
In the admin, hide the old repeater field, but leave it in place. The best way to do this is probably adding some custom CSS, but there might be other ways.
In your template create two possible code blocks, one to show the new repeater and the second to show the old repeater when the new repeater has no values.
This makes it possible to slowly convert the old to the new as the client updates the posts instead of retroactively updating every post.
There is a lot of details missing in the above explanation and you’ll need to do some searching to find it. All of it can be found on this forum, likely by me. You will need to understand how to generate values for a nested repeater using the load_value hook. This has been discussed many times here.
This would be extremely difficult to do with phpMyAdmin.
Existing repeater values in the db
meta_key | value
--------------------------------------------------------------------------
{$repeater_name} | {count($repeater_rows)}
_{$repeater_name} | {$repeater_field_key}
{$repeater_name}_{$row_index}_{$sub_field_name} | {$sub_field_value}
_{$repeater_name}_{$row_index}_{$sub_field_name} | {$sub_field_key}
what they would need to be changed to
meta_key | value
---------------------------------------------------------------------------------------------------------------------------
{$repeater_name} | {count($repeater_rows)}
_{$repeater_name} | {$repeater_field_key}
{$repeater_name}_{$row_index}_{$nested_repeater_name} | {count($nested_repeater_rows)}
_{$repeater_name}_{$row_index}_{$nested_repeater_name} | {$nested_repeater_key}
{$repeater_name}_{$row_index}_{$nested_repeater_name}_{$row_index}_{$sub_field_name} | {$sub_field_value}
_{$repeater_name}_{$row_index}_{$nested_repeater_name}_{$row_index}_{$sub_field_name} | {$sub_field_key}
See the remove_wp_meta_box setting https://www.advancedcustomfields.com/resources/acf-settings/
ACF is not required for this, but you could use it for a custom ID value. In either case you would just create a body_class filter, see https://developer.wordpress.org/reference/hooks/body_class/
You need to enclose your value in quotes
value’ => '"Melbourne"',
The values is stored as a serialized array in the database and each value is enclosed in double quotes. To look for specific values you add the quotes to the value to limit the like statement when there are multiple values that may match. The same is true when searching for a specific ID (number) value.
This topic has come up many times in the past. Here is a link to an old (closed) topic https://support.advancedcustomfields.com/forums/topic/flush-unused-custom-fields/
And [Search Results] for other topics.
I suggest that you read over these topics to understand the difficulty in doing this.
Before you begin you should know that there really is no safe way to delete old ACF field values.
Yes, there are some places where some ACF field group and field settings do not work. This is due to the WP HTML used on those pages. The place where this is seen the most is on user forms and term forms.
Is there any way to get Gutenberg blocks to show in ACF Flexible Content rows?
No.
How do I manage working with the two?
You don’t.
Gutenberg blocks and flex fields are pretty much mutually exclusive. Using both of them you could build a custom template to render both, but they would be separate entities, one appearing before the other.
There is a hook that is fired when a repeater is added, this is in JavaScript. See Adding custom javascript to fields and JavaScript API. The hook you are looking for is append.
acf/load_field and other hooks should use the field key variation for repeater sub fields. However, most of these hooks only fire once per sub field. The acf/prepare_field fires on every instance, but this only fires for existing fields and will not work when a row is added to a repeater. There is also no way of telling what row of the repeater is being prepared for render.
Without using JavaScript you would have to do what you describe in your last statement about using acf/save_post.
You are also missing the 3rd piece.
The first piece of code is JavaScript that adds a button to any form inside a element with a class of “edit-proj-form”
<div class="edit-proj-form">
ACF form added here
</div>
Then at the bottom of the page you find a 2nd JS. This is called when the button is clicked to set a hidden true false field to true.
This depends on the previous discussion about adding a field to the field group that is hidden by CSS.
When the acf/save_post action runs it is looking for this field to be set to true and it it is it deletes the post.
This is a question for people over at WooCommerce.
Yes it is. I have it set up to allow both input and textarea fields for a plugin. I use it to shoe input and textareas to allow copy and paste of shortcodes from the editor for my CPT.
<?php
add_filter('acf/prepare_field/key=field_619663d258c1e', 'shortcodes_messages', 20);
function shortcodes_messages($field) {
global $post;
if (is_a($post, 'WP_POST')) {
ob_start();
// I generate message here
$field['message'] = ob_get_clean();
}
return $field;
}
add_filter('wp_kses_allowed_html', 'allow_input_in_acf', 20, 2);
function allow_input_in_acf($tags, $context) {
$attributes = array(
'type',
'disabled',
'checked',
'style',
'name',
'value',
'class',
'id',
'style',
'readonly'
);
if ('acf' === $context) {
if (!isset($tags['input'])) {
$tags['input'] = array();
}
foreach ($attributes as $attribute) {
$tags['input'][$attribute] = true;
}
if (!isset($tags['textarea'])) {
$tags['textarea'] = array();
}
foreach ($attributes as $attribute) {
$tags['textarea'][$attribute] = true;
}
}
return $tags;
}
I’m doing the same thing in one of my custom plugins, using the most recent version of ACF and it is working.
What is the priority of your acf/prepare_field filter. Set it to something > 10 and try it again.
You would have to code it yourself and add it to functions.php or some other way.
For message fields, you cannot insert input tags into the message. These will be stripped out when the field is saved.
You need a two step process. The first you already did, and that is to allow the output of the input field.
The second step is to use an acf/prepare_field filter for the message field and generate the input HTML in php and return it in $field[‘message’]
It is not possible using a single WP_Query to sort posts by term and then by date, or visa-versa.
You can do this by doing multiple queries, one for each term.
Another option would be do sort the post array returned in the query using PHP usort() or one of the other PHP array sorting function.
You would have to use custom JavaScrpt and build your own AJAX function that continuously check the value and did the update.
There is no other way to detect a value has changed.
It is impossible to force a user’s browser to refresh from the server.
The first portion of the code in that example is added using custom JavaScript.
The second portion of code goes in your functions.php file.
ACf does not automatically delete images from the media library when they they are removed from images fields.
I have no idea how you would do this with the plugin you are using.
Just looking at ACF what you would do is create an acf/save_post action with a priority <10. In the action you use get_field() to get the current value of the field. The new value of the field will be in $_POST[‘acf’][$field_key]. The you would compare these 2 values. If the post ID for the old image is not present in new submission then you would use WP function to delete the attachment from media.
Yes, you need to use acf/save_post instead of WP hooks.
When using this hook you need to use WP functions to get the other information since it only passes the post ID and not the post data.
There are many topics on this forum about updating the post title from an ACF value.
You need to use the acf/save_post hook instead of the WP save_post hook. The WP hook fires before ACF has saved the new values to the fields.
You will have to contact the developers of your import plugin. Most of the big import plugins include premium add ons for ACF. Either that or there are filters and actions that can be used it extend them.
The value stored in a select field does not include the label. The values stored in the DB is a single text value if the select field only allows a single value. An array of text values are stored in multiple values can be selected.
The values are just the values.
There is no way to retrieve the values without using ACF.
See get_field_object() to get the labels.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.