Conditionally including JS based on whether ACF field is set [closed]

The Loop isn’t available yet in wp_enqueue_scripts, so is_single() etc pp aren’t going to work. However, the queried object has already been determined, so you could use something like add_action(“wp_enqueue_scripts”, function() { $qo = get_queried_object(); if(get_class($qo) == “WP_Post”) { if($val = get_field(“my-field”, $qo->ID)) { wp_enqueue_script(“jquery”); } } });

ACF + WPML: How to translate date fields?

You can use the global $wp_locale to get the month translated in each language. You just need to get the month number (01 to 12) from the Acf field. You have the functions in the WP_Locale class get_month() and get_month_abbrev() global $wp_locale; $month = $wp_locale->get_month(04); // Output april in english $month_abbrev = $wp_locale->get_month_abbrev($month); // Output … Read more

ACF Load Field Groups Programmatically [closed]

In case anyone needs it, this is working for my needs: add_filter(‘acf/get_field_group’, ‘my_change_field_group’); function my_change_field_group($group) { $get_current_screen = get_current_screen(); $get_current_post_type = $get_current_screen->post_type; $my_option = get_field(‘my-option’,’option’); if ( $get_current_post_type == ‘my-cpt’ && $my_option == ‘stuff’ && $group[‘key’] == ‘group_123456789’ ) { $group[‘location’] = array( array( array( ‘param’ => ‘post_type’, ‘operator’ => ‘==’, ‘value’ => ‘my-cpt’, ), … Read more

How do I show the post title if an advanced custom field hasn’t been used?

If in doubt, check the documentation first: https://www.advancedcustomfields.com/resources/get_field/ Check if value exists This example shows how to check if a value exists for a field. $value = get_field( ‘text_field’ ); if ( $value ) { echo $value; } else { echo ’empty’; } So, in for your case you would need to use: <?php $short_testimonial … Read more

ACF gives a syntaxError unexpected token

You’re missing quotes around the content of innerHTML. If correctoutput is <div></div>, then you’re script looks like this: $(‘#correcto’).innerHTML(<div></div>); Which is invalid, because you’re missing quotes. innerHTML needs a string, which is in quotes in JavaScript. That first < is where your error is coming from. So you need to do this: $(‘#correcto’).innerHTML(‘<?php the_field(‘correctoutput’); ?>’); … Read more

ACF: Hide a div or template section when a custom field (in a field group) is empty

Hope this help how to figure out your request <?php $werdegang = ‘werdegang’; // werdegang parent group $station1 = ‘jahr_station_1’; // ‘ child group 1 $station2 = ‘jahr_station_2’; // ‘child group 2 $station3 = ‘jahr_station_3’; // ‘child group 3 $station1Jahr=”jahr1″; $station2Jahr=”jahr2″; $station3Jahr=”jahr3″; $station1Title=”jahr1_Title”; $station1Text=”jahr1_Text”; $station2Title=”jahr2_Title”; $station2Text=”jahr2_Text”; $station3Title=”jahr3_Title”; $station3Text=”jahr3_Text”; ?> <?php if( (!empty($station1Title) && !empty($station1Text)) && … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)