The post_content in the database shows this:
<!-- wp:acf/alert {"id":"block_6322f7e222bc2","name":"acf/alert","data":{"style":"jd-alert-primary","_style":"field_605a25cbfd38d","content":"test","_content":"field_605a25703f166","animation":"0","_animation":"field_605d359101c4c"},"align":"","mode":"preview"} /-->
<!– wp:paragraph –>
<p>lorem ipsum</p>
<!– /wp:paragraph –>
when im logged in the custom alert block is showing when im not logged in only the <p>lorem ipsum</p> is showing.
on everything you need the second parameter , ‘option’ if its an option field
Does no one have the same problem? Blocks perfectly showing when logged in i think it has something to do with $is_preview? the_content() just doesnt apply the blocks. trying to solve it for hours
hm i think ACF is in the middle between using WP posts and a bit of custom coding. If you want to do something complete custom i would not even use ACF for the form and validation of user input and build a little submission ajax/php form by yourself.
you need to code it custom with php if you want to build a complex search for your frontend
yes its because you need to install ACF in order to use the function get_field()
i would recommend doing it because i think your theme depends on it
<p>Color: <span class="<?php echo esc_attr($color['value']); ?>"><?php echo esc_html($color['label']); ?></span></p>
i dont see any other idea.. if you want to refactor and use a different field type you need to bulk convert the old values to match your new
Do you have ACF or ACF Pro installed?
you need this: https://www.advancedcustomfields.com/resources/create-a-front-end-form/
or you could do a custom form which sets the values to your post with update_field( 'line_manager', $picked_value, $post_id );
Make a new taxonomy picker field with another name for example subject_picker
and adapt your logic if subject_picker field has a value do new logic if not do old logic.
and also maybe create terms by the old text inputs with a job. (looping all your posts, getting the field and creating term (wp_insert_term()).
then do a job and set value to all the old terms for the new subject_picker field.
Same Problem.. suddenly blocks only rendered in frontend when im logged in as wordpress user? wtf
acf frontend form itself has validation before its submitted. use acf/save_post filter to fire an additional action to save the data in your custom Database.
it would be stored in default custom fields also though..
i would do it something like:
setup database table ‘custom_events’ beforehand ofc
function insert_event(array $args = []) {
$defaults = [
'event_name' => null,
'time' => date('Y-m-d H:i:s'),
];
$values = wp_parse_args($args, $defaults);
if ( is_null($values['event_name']) ) {
return new \WP_Error("Please provide an event name");
}
global $wpdb;
$table_name = 'custom_events';
$table_name = $wpdb->prefix . $table_name;
$wpdb->insert($table_name, $values);
return $wpdb->insert_id;
}
add_action('yourprefix/events/insert', 'insert_event' );
function my_acf_save_post( $post_id ) {
// Get newly saved values.
$values = get_fields( $post_id );
// Make sure $values acf fields and your custom database fields match their names
do_action('yourprefix/events/insert', [ $values ]);
}
add_action('acf/save_post', 'my_acf_save_post');
you would need an update action aswell and also error handling its just the direction i would to it.
infact i do it same on some projects i maintain WP Post Data but additional data in custom tables
https://www.advancedcustomfields.com/resources/post-object/
this is what you need with “multiple select” option you receive an array of posts or post ids in the order the user picked or sorted it
Hi Milena,
you also of course need to adapt your woocommerce templates to output the custom fields.
Start with creating a child theme and identify the template or template part you want to edit.
then read the developer docs about how to adapt the templates with a child theme: https://woocommerce.com/document/template-structure/
i dont know what it has to do with acf but check defaults on get_posts()
it has publish as default post_status. Do you have published products?
Also is products the post_type from WooCommerce or is it a self registered? Is it correctly registered an you have product posts published?
Thanks John for this approach. i did it similiar i just save the base64 enc. image to an ACF Textfield and use this as img src where i need it.
Thank you i searched a lot finally found how to do it!
Is there a chance to additionally modify the function to only return the posts which are publish? So a combination of only posts of current author id and only published posts of that author?
thanks
@kopiczko-sebastian can confirm it works perfectly. Thanks for this!
acf_register_block_type(
array(
'name' => 'countdown',
'title' => __('Countdown', TEXTDOMAIN),
'description' => __('A custom Countdown block.', TEXTDOMAIN),
'render_template' => 'template-parts/blocks/countdown.php',
'category' => 'my-custom-blocks',
'icon' => 'calendar-alt',
'keywords' => array( 'countdown', 'date', 'time' ),
'supports' => array( 'anchor' => true )
)
);
Solved it with this so only main query is affected.
if( !$query->is_main_query() ) return;
Add this line:
if( !$query->is_main_query() ) return;
at the beginning of you filter, solved it for me
Add this line:
if( !$query->is_main_query() ) return;
at the beginning of you filter, solved it for me
Hi John,
it’s an old thread but i have the same problem what causes for me the problem is the filter: pre_get_posts
pre_get_posts function conflict with ACF Field
Hi John,
i don’t quite understand your last post but i will try to figure it out. if i find a solution i’ll update here for other users.
thanks for your help!
here the full code maybe better to see what i have in mind.
add_action('acf/save_post', 'save_customerdata', 5);
function save_customerdata( $post_id ) {
if( is_admin() ) {
return;
}
if ( $_POST['acf']['field_5fd213a8c6dfe'] != get_field('field_5fd213a8c6dfe') ) {
$plz = $_POST['acf']['field_5fd213a8c6dfe'];
}
if ( $_POST['acf']['field_5fd213f4c6e02'] != get_field('field_5fd213f4c6e02') ) {
$street = $_POST['acf']['field_5fd213f4c6e02'];
}
if ( $_POST['acf']['field_5fd21405c6e03'] != get_field('field_5fd21405c6e03') ) {
$ptel = $_POST['acf']['field_5fd21405c6e03'];
}
if ( $_POST['acf']['field_5fd21410c6e04'] != get_field('field_5fd21410c6e04') ) {
$pfax = $_POST['acf']['field_5fd21410c6e04'];
}
if ( !empty( $plz ) OR !empty( $street ) OR !empty( $ptel ) OR !empty( $pfax ) ) {
$post = get_post( $post_id );
$user_id = str_replace("user_", "", $post_id);
$user_info = get_userdata($user_id);
$first_name = $user_info->first_name;
$last_name = $user_info->last_name;
$user_email = $user_info->user_email;
$user_login = $user_info->user_login;
$to = '[email protected]';
$headers = array('From: ' . $user_info->first_name. ' '.$user_info->last_name . ' <'.$user_info->user_email.'>');
$subject = 'Profile Updated';
$body = $user_info->first_name. ' '.$user_info->last_name. ' hat das Profil aktualisiert' . "\r\n";
$body .= 'Benutzername: ' . $user_login . "\r\n";
if ( !empty( $plz ) ) {
$body .= 'PLZ / ORT wurde aktualisiert.' . "\r\n";
}
if ( !empty( $street ) ) {
$body .= 'Strasse / Hausnummer wurde aktualisiert.' . "\r\n";
}
if ( !empty( $ptel ) ) {
$body .= 'Telefonnummer wurde aktualisiert.' . "\r\n";
}
if ( !empty( $pfax ) ) {
$body .= 'Faxnummer wurde aktualisiert.' . "\r\n";
}
wp_mail($to, $subject, $body, $headers );
}
}
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.