I have a repeater for date/time data. I have a checkbox field for all_day
and then I have a start_time
and end_time
field. The all-day field is unchecked by default and then I have the start/end time fields set to be conditionally hidden if all_day
is not equal to checked
. This works fine initially when I check the all-day box, but then when I reload the page the headings for the start/end time are still visible though the actual time inputs are not.
Here’s what it looks like when I check the box initially:
And then here’s what it looks like when I reload the page:
I can’t get this to work at all, I’m trying to build into a rest_{post_type}_query but struggling to get it to work on a regular query not sure what I’m doing wrong all so I’m trying to get any results from this query between 2 dates:
$args = array(
'post_type' => 'tours',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'linked_tours', // Name of the repeater field
'value' => array( '20230822', '20230925' ), // Array of start and end dates
'type' => 'DATE',
'compare' => 'BETWEEN', // To check if the date falls within the range
)
),
);
linked_tours is the name of a repeater field on the tours post type containing 2 sub_fields, a datepicker and a post object. I’m trying to return tours between 2 dates but getting no results.
I’ve tried a few combinations on the ‘key’ that I found on the forum but none working. Sorry if this has been asked before but I haven’t found a solution and any help would be appreciated.
I have a problem to use ACF Fields (PRO version) to build up a frontend dashboard for each registered user. I tried to create the page using Elementor but any dynamic fields such as logo image and the value selected from field as city and category (created in ACF for that specific CPT) are not recognized. The idea was to build up a multistep form with amministrative data (address,VATno., legal email address and so on) and other fields that are mandatory to create a CPT Post for the registered user that has a role assigned equivalent to author. Then each user must compile the form and the data must be visible in the frontend CPT post that has the same title as the activity name ACF field. Any idea how to approach this problem?
Hi there!
I’m using a nested repeater inside a nested repeater => a list of companies containing a list of emails each. They are saved in an options page. I’m trying to update only the list of emails of a specific company via the frontend, which I managed to do with:
if(have_rows('field_64d1e8c0387f6', 'falke_amsc_options')) {
while(have_rows('field_64d1e8c0387f6', 'falke_amsc_options')) {
the_row();
$emails= get_sub_field('field_64d1e937387fa'); // 'emails'
if([condition...]) {
$counter = 0;
while($_POST["email-$counter"]) {
$newEmails[] = array( 'field_64d1e947387fb' => $_POST["email-$counter"] );
$counter++;
}
update_sub_field( 'field_64d1e937387fa', $newEmails, 'falke_amsc_options' ); // 'emails'
}
}
}
// field_64d1e8c0387f6 => 'companies' repeater
// field_64d1e937387fa => 'emails' repeater
// field_64d1e947387fb => 'email' field
Saving the new values works perfectly fine. However, my custom validation checking if any email isn’t unique isn’t triggered when saving that way. Updating the values in the backend triggers the validation normally. Not using update_sub_field()
though. Even a dummy-validation doesn’t trigger:
function falke_acf_validate_dummy( $valid, $value, $field, $input ) {
// Bail early if value is already invalid.
if( $valid !== true ) {
return $valid;
}
return __( "Don't save the values" );
} add_filter('acf/validate_value/key=field_64d1e947387fb', 'falke_acf_validate_dummy', 10, 4);
// doesn't work either
add_filter('acf/validate_value/key=field_64d1e937387fa', 'falke_acf_validate_dummy', 10, 4);
I also tried adding the filter to the repeater containing the emails instead of the email-field itself, didn’t work either. Is there anything else I need to consider? How do I trigger the validation of my e-mail-fields when updating them with update_sub_field()
?
Thanks in advance!
I’ve given up on a support ticket. I sincerely hope you good people can help with this.
I’ve written a custom plugin that among other things creates a new post type, then registers acf fields to that post type. Everything with this plugin seems to work as expected.
However, I’m now trying to use a simple script in an mu-plugin to get values from old fields made with a different custom field plugin, and save those values to the newly registered ACF fields. After the hooks ran, there was no update showing on the backend, ie the values of the acf fields were still blank.
I’m sure I’m missing something simple.
This…
function update_owner_name_value_update_field($post_id) {
$old_owner_name = old_field_name;
// verified: $old_owner_name returns string "DAVE"
if( have_rows('field_q3md98zvnm241', $post_id) ) :
while( have_rows('field_q3md98zvnm241', $post_id) ) : the_row();
update_sub_field('field_4v8yw6n2hbpqs', $old_owner_name, $post_id);
endwhile;
endif;
}
add_filter('acf/save_post', 'update_owner_name_value_update_field', 10, 1);
…seems to be adding the value, but perhaps in a newly created field rather than the registered field.
I could be wrong about that, but in the DB postmeta…
meta_key:
additional_information_0_owner_name
value:
string “DAVE”
…NOTE the 0 in this meta_key
This value does NOT appear for field_4v8yw6n2hbpqs (owner_name) on the backend post editor screen for the given $post_id following a save of that post. It can be accessed and returned using get_field with the same field key though.
On the other hand, This…
function update_owner_name_value( $value, $post_id, $field, $original ) {
$old_owner_name = old_field_name;
// verified: $old_owner_name returns string "DAVE"
if( is_string($value) ) {
$value = $old_owner_name;
}
return $value;
}
add_filter('acf/update_value/key=field_4v8yw6n2hbpqs', 'update_owner_name_value', 10, 4);
…absolutely works!
in the DB postmeta…
meta_key:
additional_information_owner_name
value:
string “DAVE”
… no zero in this meta_key.
The value for this DOES appear in field_4v8yw6n2hbpqs (owner_name) on the backend post editor screen for the given $post_id following a save of the post.
I need to be able to use the first method (update_field function) to achieve the same basic result as the second method (acf/update_value hook), wherein the the value actually shows up on the post editor screen.
Here’s my field registration function (reduced to focus on the owner_name field)…
function register_custom_fields() {
if (function_exists('acf_add_local_field_group')) {
acf_add_local_field_group(
array(
'key' => 'group_5fd8be3a8aef1',
'title' => 'Dealer Fields',
'fields' => array(
array(
'key' => 'field_q3md98zvnm241',
'label' => 'Additional Information',
'name' => 'additional_information',
'type' => 'group',
'sub_fields' => array(
array(
'key' => 'field_4v8yw6n2hbpqs',
'label' => 'Owner Name',
'name' => 'owner_name',
'type' => 'text',
),
),
)
)
)
);
}
}
This registration function runs on init, whereas the others are in an mu-plugin, and run on the hooks shown at priority 10. If this needs to be changed please advise.
Hi all, I have created an ACF Block that uses a wp_query to display a filterable list of all posts of a specific post type. My issue is that I need to be able to add more than one of these blocks to a page, but when I do, I get a critical error. If I remove the wp_query, the page will load with multiple instances of the block. Anyone have any idea what I am doing wrong? My assumption is that I need to make the wp_query unique to the block instance, but I do not know how. Any help would be greatly appreciated.
The code is pretty large so I will just include my wp_query.
$args = array(
'post_type' => 'partners',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $partner_type,
'operator' => 'IN',
),
),
);
if ($grid_hosts_weddings) {
$args['meta_query'][] = array(
'key' => 'hosts_weddings', // ACF field key for hosts_weddings
'value' => '1',
'compare' => '='
);
}
if ($grid_hosts_meetings) {
$args['meta_query'][] = array(
'key' => 'hosts_meetings', // ACF field key for hosts_meetings
'value' => '1',
'compare' => '='
);
}
$partners_query = new WP_Query($args);
Hi,
I try to use front-end forms.
I registered form and use it in template.
add_action('init', 'init_forms');
function init_forms()
form_register();
}
function form_register()
{
if (is_admin() || is_admin_login_page()) {
return;
}
$pageAccount = get_page_with_shortcode('ACCOUNT_SHORTCODE');
$permalinkAccount = get_permalink($pageAccount->ID);
if (empty($permalinkAccount)) {
$permalinkAccount = '';
}
if (check_current_url_equals_shortcode('ACCOUNT_SHORTCODE_REGISTER')) {
acf_register_form(array(
'id' => 'new_member',
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'member',
'post_status' => 'publish',
),
'honeypot' => true,
// 'field_groups' => array('group_64ae62c8e220b'),
'fields' => [
LASTNAME_FIELD,
FIRSTNAME_FIELD,
EMAIL_FIELD,
EMAIL_FIELD . 'repeat',
PHONE_FIELD,
PASSWORD_FIELD,
PASSWORD_FIELD . 'repeat',
GENDER_FIELD,
],
'form' => true,
'updated_message' => __('Informations saved !', 'onlyweb'),
'submit_value' => __('Save profile', 'onlyweb'),
'html_submit_button' => '<input type="submit" class="btn acf-button button button-primary button-large" value="%s" />',
'return' => add_query_arg(array('updated' => 'true'), $permalinkAccount),
));
}
}
I added validation for field like exmple below :
add_filter('acf/validate_value/key=' . EMAIL_FIELD . 'repeat', 'my_acf_validate_check_login_are_same', 10, 4);
function my_acf_validate_check_login_are_same($valid, $value, $field, $input)
{
// bail early if value is already invalid
if (!$valid) {
return $valid;
}
if (!is_admin()) {
// Remove all errors if user is an administrator.
if (current_user_can('manage_options')) {
acf_reset_validation_errors();
}
$login = (!empty($_POST['acf'][EMAIL_FIELD])) ? $_POST['acf'][EMAIL_FIELD] : false;
$loginRepeat = (!empty($_POST['acf'][EMAIL_FIELD . 'repeat'])) ? $_POST['acf'][EMAIL_FIELD . 'repeat'] : false;
if ($login != $loginRepeat) {
$valid = __('Email are not the same !', 'onlyweb');
$valid = 'error 2';
// return $valid;
}
}
return $valid;
}
The problem appears when I submit the form, error are shown on an other error page.
Any solution ?
Here is my scenario:
Setting up a school planner/organization system where teachers can add subject resources per week per student…but to make this quick and useful, I want to make the resources “reusable”.
So for instance, if a teacher is adding a book resource for “Student A” within a repeater field labeled “books”, they would type the title and save it so now “Student A” can see that resource on their assignment page. However, what if that teacher wanted another student to use the same resource OR maybe a student the following school year would need to use it…I would like that resource to be available in a post type for them to have the option of using a relationship field for “past resources”.
I know I can do this by having the post type setup and having the teachers add all resources there first, then go into the student page and call up the resources: BUT, this is not user friendly. I really want the teachers to be able to work on a weekly plan for a student and add things within a singular page for that student…and then have all those things “saved” into a separate post type that would essentially be a resource library. Ideally they would be able to add tags to the resource as well so that all gets “exported” over into the resource CPT.
I would be using either repeater or flexible content fields on the student pages…so that’s where the resource data would be needing pulled from into a CPT…
Anyone know how I can do this????
I have regular posts (articles about a subject) and a Custom Post Type (to generate a page about a subject).
Can I bring in a post category into a custom post type field (that queries the post category) so I can edit that post from a custom post type edit page?
I have all the relationships etc. and can display the custom post type template and its fields, and the posts related on the front end, but I want to be able to fill out the custom field data AND edit the related posts in one place in the back end.
Is this possible? Is this stupid?
Hi,
Something very weird.
I made some custom functionality to make it happens the way I need, I’ll write here all the flow:
– I have created a new custom post type called event
. I also created a custom taxonomy under event
called event_type
.
– I created from GUI a field-group with tabs and in every tabs there are custom fields.
– In one of the tabs(last of them) there is a repeater and a sub-repeater.
– Inside this sub-repeater there is a group, and under this group(let’s call it specific-event
), I have SELECT field which I populate all terms from the custom taxonomy event_type
.
– I want that in the SELECT under the specific-event
, when the user picks a term, it will show custom group under specific-event
with custom fields.
So what I did:
I have created programmatically each group and set the parent
attribute to be specific-event
field key.
Each group automatically gets ‘hidden’ class.
In the JS API, I have created some logics, to detect any term select and make the correct group(I have created programmatically) to be visible.
– So far all good, the custom functionality seems to be working,
Everytime I change the term in the select under specific-event
it shows me the correct sub-group under specific-event
.
BUT, when I add lets say 7 parent rows in the parent repeater, and inside I add more 3-4 sub-rows each,
It doesnt save all… after saving I gets only 4 parent rows, and not 7. Something very very wierd.
This is the code for the custom groups:
add_action('init', function() {
if (function_exists('acf_add_local_field_group')) {
acf_add_local_field(array(
'key' => 'field_event_event',
'label' => 'נקודת עניין',
'name' => 'event__event',
'aria-label' => '',
'type' => 'select',
'choices' => array(),
'return_format' => 'array',
'ui' => 1,
'multiple' => 0,
'parent' => 'field_6441222b20c40'
));
acf_add_local_field(array(
'key' => 'field_event_time',
'label' => 'זמן',
'name' => 'event__time',
'aria-label' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'taxonomy' => '',
'parent' => 'field_6441222b20c40'
));
$event_types = get_terms([
'taxonomy' => 'event_type',
'hide_empty' => false,
]);
foreach ($event_types as $event_type) {
$dynamic_fields = (!empty(TL_ACF::get_field('event-type__dynamic-fields', 'event_type_' . $event_type->term_id)) ? TL_ACF::get_field('event-type__dynamic-fields', 'event_type_' . $event_type->term_id) : array());
$field_group = array(
'key' => 'field_' . $event_type->term_id,
'label' => $event_type->name,
'name' => 'event__type-' . $event_type->term_id,
'type' => 'group',
'wrapper' => array(
'class' => 'hidden',
),
'parent' => 'field_6441222b20c40'
);
foreach ($dynamic_fields as $dynamic_field) {
$field_group['sub_fields'][] = array(
'key' => 'field_' . $dynamic_field['dynamic-fields__system-name'],
'label' => $dynamic_field['dynamic-fields__name'],
'name' => 'type-' . $event_type->term_id . '__' . $dynamic_field['dynamic-fields__system-name'],
'type' => $dynamic_field['dynamic-fields__type']['value'],
);
}
acf_add_local_field($field_group);
}
}
});
Hi,
I have recently updated ACF free to ACF Pro, at that moment i could fill in a license number. But now i cannot check the update page anymore. It throws an error:
This is an error in local dev environment, but the issue is also in staging and live env.
Fatal error: Uncaught Error:
Call to undefined method acf_updates::get_plugin_update() in /app/public/wp-content/plugins/advanced-custom-fields-pro/pro/admin/admin-updates.php:191 Stack trace:
#0 /app/public/wp-includes/class-wp-hook.php(308): ACF_Admin_Updates->load('')
#1 /app/public/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#2 /app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /app/public/wp-admin/admin.php(237): do_action('load-acf_page_a...')
#4 /app/public/wp-admin/edit.php(10): require_once('/Users/pieter/L...')
#5 {main} thrown in /app/public/wp-content/plugins/advanced-custom-fields-pro/pro/admin/admin-updates.php on line 191
The line where the error is referring to in the code, the $update line:
// perform update checks if license is active
$basename = acf_get_setting( 'basename' );
$update = acf_updates()->get_plugin_update( $basename );
URL: /wp-admin/edit.php?post_type=acf-field-group&page=acf-settings-updates
What can i do 🙂 ?
I found this
https://support.advancedcustomfields.com/forums/topic/how-to-create-repeater-field-up-and-down-buttons/#post-162165
But there was no support on it so I would like to make an official request.
When my repeater block item has many fields in it, it makes the item block very large and making it very difficult to re-arrange them by drag and drop only. Many times I have to zoom far out from the browser to make it work. This is extremely relevant with using ACF to create gutenberg blocks as the edit section of the preview block is very limited.
It would be awesome if when hovering over the drag and drop area that if the block is over [xxx]px tall then up and down buttons appear near the top and bottom of the drag and drop area. Clicking on them just moves the block up or down one spot accordingly.
If the item block height is not that tall then it might not make sense to show or need the buttons as there may not be enough room for them.
Thanks
im trying to display acf field in woocommerce product-data -> general tab
add_action('woocommerce_product_options_general_product_data', 'add_custom_file_upload');
function add_custom_file_upload() {
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_12uyy',
'title' => 'My Group 123',
'fields' => array (
array (
'key' => 'field_1',
'label' => 'Sub Title light',
'name' => 'sub_title_light',
'type' => 'file',
'prefix' => '',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
)
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
));
endif;
}
but when im trying to hookup acf field with woocommerce_product_options_general_product_data, its not displaying
im trying to display acf field in woocommerce product data > genreal tab
add_action('woocommerce_product_options_general_product_data', 'add_custom_file_upload');
function add_custom_file_upload() {
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_12uyy',
'title' => 'My Group 123',
'fields' => array (
array (
'key' => 'field_1',
'label' => 'Sub Title light',
'name' => 'sub_title_light',
'type' => 'file',
'prefix' => '',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
)
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
));
endif;
}
im trying to hook acf field-> file type with woocommerce_product_options_general_product_data but im unable to display acf field type in woocommerce hook.
acf field is not displayed in product data -> general tab
Hi there,
I need help in showing the ACF fields that I’ve created in WooCommerce Add New Product Page for a specific category only. That specific category would have some sub-category and I would like to include those as well. I can’t choose Post Type as Product because I have different fields customized for different product category.
Currently, I could only make it to show in the Edit Product Page. If I choose the location rules as Post Taxonomy for a certain product type or product cat, then it’ll only show those ACF fields in the Edit Product Page as that particular post is published, and so it has its own taxonomy queried. However, before the post is published (add new product page), it would not show since it doesn’t have any taxonomy query yet.
Is there anything that I can set to make this work or any advice on this? Would appreciate very much for the help given. Thanks
I need a custom field with a map that defaults to a specific GPS Location when it appears in the backend of posting a bbpress topic. Once it shows up there needs to be the ability for the poster to move the marker to a specific location. When they post it the frontend will show the address, GPS Coordinates, or at least show the marker on the map.
I have a ACF map plugins installed. I have API keys for Here, Mapquest, Google. I have the Leaflet and OpenStreetMaps ACF plugins.
Here is my problem.
A. Google Maps does what I want on the backend perfectly, but on the frontend it only gives coordinates, not a map. I read about some kind of API issue,and that several files need to be edited.
B. I have tried OpenStreetMaps several different ways, but on the backend, the marker will not move even thought it says it can be moved. (plus it has Hamburg germany as the default map.)
C. Leaflet lets you drag the marker put it does not show a map in the backend the frontend.
Help!
I’m using ACF Pro to create a Learning Management System. I’ve only recently started having problems. The main one that’s giving me the most trouble is that update_field()
is not actually updating the field, despite me giving it accurate information and it working on a local environment (but not a WP Engine Dev environment).
Currently I’m allowing the user to create a new Course (or “Module”), based on a previous one, specifically for their class. They choose which students they’ll be including, the Module to use a template, then the Chapters (or “Documents”) from that Module.
Then, on the final screen, they review information, and the “Submit” button starts through a series of AJAX calls that sends the information to the server, sends back the pertinent info, then moves on to the next step.
I’m sending back the results from each delete_field()
and update_field
command. When replacing values, I am deleting the current value (with delete_field()
) before using update_field(). This has helped some of my issues, but not all.
Here is the pertinent PHP code:
<?php
// I've made the CPT "Module" its own Class to contain its helper methods
$module = new ACF_Module( intval($module_id) );
// I store the Documents (or "Chapters") for each Module (or "Course") as a
// repeater field containing the document_id and the order it should
// appear within the Module.
$document_ids = json_decode( $_POST['document_ids']);
$documents_field = [];
$count = 1;
foreach( $document_ids as $document_id ) {
$documents_field[] = [
'document_id' => intval($document_id),
'order' => floatval($count),
];
$count++;
}
// In JS, $documents_field_deleted = (bool) true
$documents_field_deleted = delete_field($module->documents_field, $module->ID);
// In JS, $documents_field_updated = (int) 625785,, or a similarly large number,
// which does not correlate to ANY existing post ID or user ID, as the
// newest post_id in this example is 43113 and largest user ID is 1126
$documents_field_updated = update_field($module->documents_field, $documents_field, $module->ID);
I don’t know that this will matter, but just in case, here’s my JS doing the AJAX calls:
// Triggered when clicking submit button labelled "Next"
$('#submit').click(function(e){
e.preventDefault();
// I'm just storing values in hidden <code><input></code> fields. Since these
// classes are all taken on a job-site, where the student is
// monitored, I'm not concerned as much for the user being able to
// change these.
var nextAction = '';
actionStep = $('input[name="acf_action_step"]').val();
var payload = {
action: 'acf_action_function_name',
action_step: actionStep,
agency_id: parseInt($('input[name="acf_agency_id"').val()),
module_id: parseInt($('input[name="acf_module"]').val())
};
switch (actionStep) {
case 'module':
payload.module_title = $('input[name="acf_module_title"]').val();
nextAction = 'chapters';
break;
case 'chapters':
payload.chapter_ids = $('input[name="acf_chapters"]').val();
nextAction = 'user';
break;
case 'user':
var user_object = JSON.parse( $('input[name="acf_users"').val() );
nextAction = 'user';
if( user_object.length == 1 ) {
nextAction = 'finish';
}
payload.user_id = parseInt( user_object.shift() );
user_ids = JSON.stringify(user_object);
$('input[name="acf_users"]').val(user_ids);
break;
case 'finish':
$('#submit').prop('disabled', true);
$('#submit').addClass('disabled');
return;
default:
break;
}
$.ajax({
url: ajax_object.ajax_url,
type: 'post',
data: payload,
beforeSend: function(){
$('#submit').prop('disabled', true);
$('#submit').addClass('disabled');
},
success: function(response) {
var response_object = JSON.parse(response);
progress.append(response_object.message);
if( response_object.new_module_id ) {
$('input[name="acf_module"]').val( parseInt(response_object.new_module_id) );
}
},
complete: function(response) {
$('input[name="acf_action_step"]').val( nextAction );
$('#submit').prop('disabled', false);
$('#submit').removeClass('disabled');
}
});
return;
});
Hy Guys, i´m new to ACF and did not get any output with acf shortcodes.
for example: [acf field="datum_news"]
Custom Short Code works:
add_shortcode( 'footag', 'wpdocs_footag_func' );
function wpdocs_footag_func( $atts ) {
return "foo = {$atts['foo']}";
}
Any hints? ACF 6.2.0 and Themify Ultra Theme
Regards Christian
Hello, i want to give the user the ability to update his social media links on frontend. However, the update_field is working, but when i send the form, i have to refresh the entire page to get the new value of the field.
function feldgruppentest() {
ob_start(); // Pufferung starten
// Überprüfen, ob der Benutzer eingeloggt ist
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
// Profil ID des aktuellen Benutzers auslesen
$lwb_profile_id = get_field('lwb_profile_id', 'user_' . $current_user->ID);
}
$fieldgroup = get_field_object('lwb_social_media', $lwb_profile_id)['sub_fields'];
echo '<form method="post" id="social-media-update-form">';
foreach ($fieldgroup as $link) {
// Feldinformationen sammeln
$field_name = $link['name'];
$field_label = $link['label'];
$field_key = $link['key'];
$field_value = get_field('lwb_social_media_' . $field_name, $lwb_profile_id);
?>
<label for="<?php echo $field_name; ?>"><?php echo $field_label; ?></label>
<input type="text" name="<?php echo $field_name; ?>" id="<?php echo $field_label; ?>" value="<?php echo esc_attr($field_value); ?>" required>
<?php
}
echo '<input type="submit" name="update_social_media" value="Speichern">';
echo '</form>';
// Wenn das Formular abgesendet wurde
if (isset($_POST['update_social_media'])) {
$value = sanitize_text_field($_POST['lwb_social_media_tiktok']);
update_field('lwb_social_media_lwb_social_media_tiktok', $value, $lwb_profile_id );
echo '<p>Das Profil wurde erfolgreich gespeichert.</p>';
//wp_safe_redirect( home_url('/mein-konto/'));
} else {
echo '<p>Du musst eingeloggt sein, um dein Profil zu ändern.</p>';
}
return ob_get_clean(); // Rückgabe des gepufferten Inhalts
}
add_shortcode('Profilinformationen', 'feldgruppentest');
Hi there,
I have a group of fields, one of the sub-fields is a Select which is populated from an API. I then have 4 other sub-fields that I want to populate based on the value in the Select, this will be via an admin-ajax call. I should be able to do this using the JavaScript API but I am struggling to get acf.getField to use the sub-field. The documention doesn’t talk about sub-fields at all so I am wondering if I am missing something here? Any pointers? Clues?
This is what I have:
(function($) {
// make sure acf is loaded, it should be, but just in case
if (typeof acf == 'undefined') {
return;
}
var acf_field = acf.getField('field_64d20c8aa2224');
acf_field.on("change ready", function(e){
// bail early if no ajax
if( !acf.get('ajax') ) return;
// abort XHR if it's already running
if( this.request ) {
this.request.abort();
}
// set the ajax action that's set up in php
var data = {
action: 'newbury_admin_get_raceday_details',
racedayId: acf_field.val(), //The key_name needs to be the name of the parameter in your action
}
this.request = $.ajax({
url: acf.get('ajaxurl'), // ajax url, acf already sets this
data: acf.prepareForAjax(data), // another included acf function
type: 'post', // posted values, look at $_POST in your php ajax action function
dataType: 'json', // how we want the date returned
success: function( json ){
console.log( json );
}
}); // end ajax
});
$('#acf-field_64d20c27a2223-field_64d20c8aa2224').trigger('ready');
})(jQuery);
Hi, I have this modified code from ‘TheDeadMedic, transfered by Viktor Dite’
<?php
/**
* Plugin Name: Email on New Post
* Plugin URI: http://wordpress.stackexchange.com/questions/19040/alert-email-when-any-post-or-page-is-changed
* Description: Send an email notification to the administrator when a new post of type "Entrada" or "circulars" is published.
* Author: TheDeadMedic, transfered by Viktor Dite
* Version: 1.0
* Copyright CC share alike
*
* @param string $new_status
* @param string $old_status
* @param object $post
*/
function wpse_19040_notify_admin_on_publish( $new_status, $old_status, $post ) {
if ( $new_status !== 'publish' || $old_status === 'publish' ) {
return;
}
// Check if the post type is 'post' (Entrada) or 'circulars'
if ( $post->post_type !== 'post' && $post->post_type !== 'circulars' ) {
return;
}
// Recipient
$emailto = 'EMAIL';
// Email subject and message for 'post' (Entrada)
if ( $post->post_type === 'post' ) {
$subject = '🌐 Nueva Entrada publicada: \'' . get_the_title( $post->ID ) . '\'';
$message = get_permalink( $post->ID );
}
// Email subject and message for 'circulars'
if ( $post->post_type === 'circulars' ) {
$subject = '📢 Nueva Circular publicada: \'' . get_the_title( $post->ID ) . '\'';
$message = get_field('circular_id', $post->ID); // Assuming 'circular_id' is the name of the custom field
}
wp_mail( $emailto, $subject, $message );
}
add_action( 'transition_post_status', 'wpse_19040_notify_admin_on_publish', 10, 3 );
?>
The ACF value get_field(‘circular_id’, $post->ID) is set, but the email is not send because it detects that there is not a value in circular_id. Any help?
Thanks.
I realise this is a big ask but I can’t work out how to do this.
I have an options page that generates publications that are just a PDF link.
It asks for a featured image, excerpt, PDF link, and date
I also have a custom post type called ‘publications’
I am trying to merge these two together and then output them sorted by date (the date picker for the repeaters and the published date for posts)
My Repeater field is setup like so:
<?php if ( have_rows( 'publications', 'option' ) ) : ?>
<?php while ( have_rows( 'publications', 'option' ) ) : the_row(); ?>
<?php the_sub_field( 'publication_name' ); ?>
<?php $publication_image = get_sub_field( 'publication_image' ); ?>
<?php if ( $publication_image ) : ?>
<img src="<?php echo esc_url( $publication_image['url'] ); ?>" alt="<?php echo esc_attr( $publication_image['alt'] ); ?>" />
<?php endif; ?>
<?php the_sub_field( 'publication_description' ); ?>
<?php $publication_file = get_sub_field( 'publication_file' ); ?>
<?php if ( $publication_file ) : ?>
<a href="<?php echo esc_url( $publication_file['url'] ); ?>"><?php echo esc_html( $publication_file['filename'] ); ?></a>
<?php endif; ?>
<?php the_sub_field( 'file_link_description' ); ?>
<?php the_sub_field( 'pdf_date' ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php // No rows found ?>
<?php endif; ?>
My custom post type is just called ‘publications’
ACF have said I need to:
Create a Custom Post Type: First, you’ll want to create a custom post type specifically for the publications (e.g., “Publications”).
Set up ACF Repeater Field: Set up an ACF repeater field group for the additional content that doesn’t fit the typical blog post format. This repeater field can include fields for an image, text, link, and date field (if you want to order by date).
Add Content as Custom Posts or Repeater Fields: For the actual blog posts, create them using the standard WordPress post editor, and assign the “Publications” custom post type to them. For the other content that consists of just an image and a link to a PDF, use the ACF repeater field to add that information to a specific page or a custom options page.
Custom Query to Retrieve and Display Content: Now comes the part where you combine both types of content on your publications page. In your page template (or a custom template), you’ll use a custom query to fetch both the regular blog posts and the ACF repeater field data.
a. Retrieve Blog Posts: Use a regular loop or WP_Query to get the blog posts assigned to the “Publications” custom post type, and display them in a list or grid format.
b. Retrieve Repeater Field Data: To fetch the data from the ACF repeater field, you can use the get_field function with the appropriate field name and iterate through the rows to display the image, text, and link.
c. Merge and Sort: Combine the data from both sources into a single array or object and sort them based on the publishing date (you can use the date field in the repeater field).
Display the Combined Content: Finally, loop through the sorted and merged array/object to display all the content together on the publications page.
Remember that the actual implementation may vary depending on your specific use case and the structure of your theme. Always make sure to properly sanitize and validate any user-generated content to ensure security.
This approach should allow you to have a flexible publications page that can include both traditional blog posts and the ACF repeater field content, presented in a unified manner sorted by date.
But I don’t know how to do this.
Any help would be greatly appreciated
Thanks
I have created a field group which is set to be visible for Taxonomy if it’s equal to Tag (post_tag). I can see the field with it’s default value when editing tag but I can’t get that value in my code. I always get it returned as null.
How I’m trying this field value:
$term = get_queried_object();
$field_value = get_field('tag_', $term->term_id, 'about_schema');
I tried var_dump($term) and it returns me this:
object(WP_Term)#8411 (10) { ["term_id"]=> int(7346) ["name"]=> string(13) "Hedera (HBAR)" ["slug"]=> string(11) "hedera-hbar" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(7346) ["taxonomy"]=> string(8) "post_tag" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(12) ["filter"]=> string(3) "raw" }
In this var_dump I can’t see the values added from ACF field.
What I’m doing wrong here?
I’m trying to use ACF Pro to create a form that people can submit, which should then create a draft post.
The ACF Field Group is there and renders on the page.
Upon submitting the form, it does display a positive confirmation message but no post has been created.
What am I doing wrong?
I have created a custom theme with the following file:
<?php
acf_form_head();
get_header();
?>
<div id="content">
<div class="wrap">
<form id='post' class='acf-form' action='' method='post'>
<?php
acf_form([
'field_groups' => ['group_5***d'],
'post_id' => 'new_post',
'post_title' => false,
'post_content' => false,
'post_category' => 'academy',
'form' => false,
'submit_value' => __("Submit post", 'acf'),
'updated_message' => __("Thank you!", 'acf'),
'html_updated_message' => '<div id="message" class="updated"><p>%s</p></div>'
]);
if(current_user_can('activate_plugins')) {
acf_form([
'field_groups' => ['group_5***b'],
'post_id' => 'new_post',
'post_category' => 'academy',
'form' => false
]);
}
?>
<div class="acf-form-submit">
<input type="submit" class="acf-button" value="Submit post">
<span class="acf-spinner"></span>
</div>
</form>
</div>
</div>
<?php get_footer();
And I have the following code snippet:
function savePostsAsAcademyDraft($post_id) {
$term = get_term_by('slug', 'academy', 'category');
wp_update_post([
'ID' => $post_id,
'post_status' => 'draft',
'post_category' => [/*$term->id*/3]
]);
return $post_id;
}
add_filter('acf/pre_save_post' , 'savePostsAsAcademyDraft', 10, 1);
Is it possible to set up CPT & taxonomy like this:
/archive-for-the-CPT/ – the archive page
/archive-for-the-CPT/%category-name%/ – the category page under the CPT & archive
/archive-for-the-CPT/%category-name%/%postname%/ – the actual post/url
I am struggling hard to work this out. Assuming a permalink rewrite plugin is needed here?
Thanks in advance.