Need this solved as well! Causes information loss with ACF WYSIWYG fields when using mqTranslate.
@bokorir I’m trying to achieve almost the same result using select2: the main difference is that I’m querying an external source (MongoDB returning json data).
I have copied most of the code from the taxonomy field and I looked at post_object, too.
As you, if I specify
$field['ui'] = 1;
the select field is rendered in the HTML code but it remains hidden.
If I remove the ‘ui’ setting or change it to 0, the select field is shown but it is disabled.
Did you manage to solve this problem?
Thanks,
Roberto
This is really a general WP question and not specific to ACF. I built a plugin that does this using shortcodes https://github.com/Hube2/blunt-snippets. There are other plugins available that work the same way, like this one: https://wordpress.org/plugins/allow-php-in-posts-and-pages/
As far as entering PHP directly into a WYSIWYG editor, I don’t know how you’d do that and to be honest I don’t think it’s a good idea.
I had similar problems and it seems that update_sub_field function is bit buggy at the moment. However, I managed to update existing repeater subfield with following code, it seems exactly like yours but it’s wrapped in have_rows() loop:
// field_54d5f40bbbe1d = repeater
// field_54e4513b63547 = subfield
if( have_rows('field_54d5f40bbbe1d', $post_id) ):
$row_index = 0;
while ( have_rows('field_54d5f40bbbe1d', $post_id) ) : the_row();
$row_index++;
// just some generic conditional logic to update specific sub_field, in this case by 'name' sub_field
if(get_sub_field('name') == $what_i_want_it_to_be){
update_sub_field( array("field_54d5f40bbbe1d", $row_index, "field_54e4513b63547"), 'test', $post_id);
}
endwhile;
endif;
I think looping this through have_rows() shouldn’t have anything to do with updating sub field. Hope this helps.
Hi @cvelez27,
You have a syntax error in your code. Your are missing a $
for the variable $shortcode
. Change your code to the following: <?php $shortcode = get_field(’ request_demo_shortcode’); echo do_shortcode($shortcode); ?>
Also you need to ensure that $shortcode contains the correct data. print_r($shortcode);
to find out if it has any data.
Right now, types of reasons behind transferring collected from one of spot to yet another. A few of these tend to be: modify inside the career, exchange associated with task in order to some other place, regarding increasing the best of life, getting greater setting as well as some people. That’s why, it is necessary you understand before hand as to the reasons you need to shift towards the additional location. It’s also crucial in respect of whether or not the transferring organization offers those with your related data as well as certainly not with regard to changing the items. Even more, it’s also possible to see the on the net critiques regarding earlier shoppers as a way to understand the particular standing regarding transferring business.
http://www.packersmoversdirectory.in/packers-movers-pune.html
http://www.packersmoversdirectory.in/packers-movers-mumbai.html
http://www.packersmoversdirectory.in/packers-movers-hyderabad.html
I don’t think there’s a way to trigger the save outside of actually saving the post to get ACF to do it’s thing.
If your looking to get a list of fields, if you know the group_id for the field group in question you can use:
acf_get_fields($group_id)
That will return a the list of fields, then you could loop through that list of fields to get the information for each field type and get the data based on that.
EDIT: I mean the group key, will look something like “group_123456789abcfef”
This is more of a general WP question. You’d used the WP function is_logged_id() to test to see if the user is logged in and then show or not show the fields based on that. http://codex.wordpress.org/Function_Reference/is_user_logged_in
You can’t use WP_Query to query based on repeater sub-fields. See this page for more information: http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/
I thought I had this – I’m sure I’m close but it doesn’t work
if( $images ): ?>
<div>
<ul class="slides">
<?php foreach( $images as $image ): ?>
<li>
<?php $image_url = $image['url']; ?>
<?php $content="<img src='$image_url' />"; ?>
<?php if ( function_exists('slb_activate') ) ?>
<?php $content = slb_activate($content); ?>
<?php echo $content; ?>
<p><?php echo $image['caption']; ?></p>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif;
Hi @flyingeagle,
ACF does not offer any way of overriding this so the best solution would be to create your own custom shortcode to display the value as an unordered list. Copy the following code to your functions.php file:
<?php
function custom_acf_shortcode( $atts ) {
// extract attributs
extract( shortcode_atts( array(
'field' => '',
'post_id' => false,
'format_value' => true
), $atts ) );
$value = get_field( $field, $post_id, $format_value );
if( is_array($value) )
{
$ul = '<ul>';
foreach($value as $val) {
$ul .= '<li>' .$val. '</li>';
}
$ul .= '</ul>';
$value = $ul;
}
return $value;
}
add_shortcode( 'custom_acf', 'custom_acf_shortcode' );
Then use it as follows: [custom_acf field="field_name" post_id="123"]
Hope this helps 🙂
@semanalitics I believe the s:4 is the length of the string value.
For instance, in my database, I have this:
s:14:”Walk-in closet”
And
s:16:”Washer and dryer”
Note the values equal how many characters follows.
I found your thread trying to figure out how to update the values globally (to fix typos) without editing the values and resaving every page that used it. Figured I’d help you while continuing to look for my answer. 🙂
Cheers.
Hello Buddies,
It took me HOURS, and i don’t get every line of code i used, but I just coded what may make your day !
WHAT I WANTED : I wanted to dynamically populate certain fields from a gravity form, using values from repeater subfields i had on an option page.
So, here it is :
add_filter("gform_pre_render_ID", "dynamic_populate");
// Update the 'ID' to the ID of your form (You have it in URL while modifying the form). This hook happens each time your form is loaded (Pre_render).
function dynamic_populate($form) {
foreach($form['fields'] as &$field){
//At this point, function will run for each field in my Gravity Form, but right after i add a condition, see what's next.
if(strpos($field['cssClass'], 'dynamicfield') === false)
continue;
//Condition : each field which has the class dynamicfield (example). If it doesn't then, continue ! Don't forget to add a class to the field you want to dynamically populate in your form. PS: You can add whichever condition you want. Example : Run only on select fields, run only on select fields AND classname...
global $wpdb;
$rows = $wpdb->get_results($wpdb->prepare(
"
SELECT *
FROM $wpdb->options
WHERE option_name LIKE 'REPEATERNAME_%%_SUBFIELDNAME'
"
));
//Call WP Database and SELECT all data FROM the table you want, for me it was option table as my repeater is on an option page. Then find each rows WHERE option_name value is like 'REPEATERNAME_%%_SUBFIELDNAME'. To get this, read the data naming convention part in here : http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/.
//If your repeater isn't on an option page, you might want to call FROM wp_postmeta WHERE meta_key LIKE 'REPEATERNAME_%%_SUBFIELDNAME'.
$choices = array(array('text' => 'Choisissez une base', 'value' => ' '));
//Default choice for my dynamic select field. You shall not use any value, so if it's required it won't validate.
if( $rows ){
foreach( $rows as $row ) {
//If there are results, for each result, find the 'repeater row number'
preg_match('_([0-9]+)_', $row->option_name, $matches);
//Note that option_name is the name of the column from my option database, you might want to change it.
$name = 'REPEATERNAME_' . $matches[0] . '_SUBFIELDNAME';
$value = get_option($name);
//Get the subfield value from the row.
$choices[] = array('text' => $value, 'value' => $value);
//Create an option array for each subfield value.
}
}
$field['choices'] = $choices;
//Once we've looped through all of the subfields values and created all of our options, we assign the $choices array (which has all of our new options) to the $field choices property.
}
return $form;
//Display the new dynamically populated form.
}
I hope this is quite clear cause i’m not a PHP expert, and i’m also french so maybe my english isn’t that good.
Tell me if it worked for you, and if you were looking after it.
PS: Eliott, thanks for the powerful ACF Plug-in, i hope that solution will help i think it’s quite useful and powerful ! Or maybe i did a hell of a job for nothing that much interesting haha !
Have a great day all!
Check my sources :
Dynamic populate Gravity Forms fields before Form pre-render => http://www.gravityhelp.com/documentation/gravity-forms/knowledge-base/tutorials/dynamically-populating-drop-down-fields/
Querying the database for subfields values => http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/
I would like to present an alternative solution as the one marked above didn’t work for me. This is how i did it, since i needed to keep the while loop and had to use get_sub_field();
Hope anyone can find it useful.
$flexible_row_number = 1;
//Count rows
$flexible_row_count = count( get_field("flexible_content_field_name") );
//Create random number out of number of rows.
$flexible_row_rand = rand(1, $flexible_row_count);
// check if the flexible content field has rows of data
if( have_rows('flexible_row_flexible') ):
// loop through the rows of data
while ( have_rows('flexible_row_flexible') ) : the_row();
//check if flexible row number equals random row number.
if ( $flexible_row_number == $flexible_row_rand ):
if( get_row_layout() == "layout"):
endif;
//If they do equal, add 1 to $flexible_row_number;
$flexible_row_number++;
else :
//If they dont equal, add 1 to $flexible_row_number;
$flexible_row_number++;
endif;
endwhile;
endif;
I think it’s quite natural that it does it since you are getting the field but I would too very much appreciate a way to sidestep the filter because if you’re calling get_field from within that hook you will end up in an infinite loop. Maybe using a parameter for the get_field_object method?
Hi @Pipoulito
On second thought, it may be possible, however, the performance would be quite slow.
Please read over this doc to get some starter code:
http://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/
Thanks
E
I wanted to update everyone in this thread on a solution I found to the activation error problem. Obviously it might not apply in every case, but it’s worth trying to make sure it’s not easily fixable.
I have the same activate issue described in several posts (before trying to activate and another error after trying to activate). This was on a site that was previously activated and functioning fine. Upon further inspection, I also noticed that my Gravity forms Developer license would not activate either (similar symptoms). This let me know it most likely wasn’t only an ACF issue, but something was effecting both plugin activation methods.
My Solution:
After about 2 hours of trying to figure out a solution, I ended up downloading the newest core files from wordpress.org and re-uploading them to the site (be careful not to overwrite your wp-content folder). This instantly fixed the issue for both plugins. I made no other changes to the site files. It was the same version of WP that was installed already (so no a version issue).
My only guess is that there was some sort of error in the core WP files from an incomplete WP update that was effecting the activation calls. I wasn’t getting any PHP errors, so I can’t pin down exactly what was happening.
If you’re having issues, I would suggest trying a re-install of the core files for a quick attempt at fixing the problem. Hopefully it will help some of you.
Hi @gerah,
First, specify the return value for the file field as the ‘File URL’ from the field group edit screen, then use then use the following code on the front-end to create a download link for the uploaded file:
<a href="<?php the_field('field_name'); ?>" >Download File</a>
For more information on this, have a look at: http://www.advancedcustomfields.com/resources/file/
Are you using a checkbox field or a true/false field.
Checkboxes are stored as serialized data and you’re not going to be able to use WP_Query to filter by a checkbox field.
If you use a true/false field then you can use WP_Query, the values of a true/false field are 0 (zero) for false and 1 for true.
the last code example you have should work for a true/false field if use substitute 0 & 1 where you have true and false.
I used your code, Tim and am getting this PHP error:
Error while parsing PHP: syntax error, unexpected 'else' (T_ELSE)
my code:
<?php if ( get_field( 'btn_show' ) ); ?>
<p class="text-center"><a class="btn" href="<?php the_sub_field('btn_url'); ?>"><?php the_sub_field('btn_text'); ?></a></p>
<?php else: // field_name returned false ?>
<?php endif; // field_name ?>
Hi @mak,
This question was answered here: http://support.advancedcustomfields.com/forums/topic/advanced-custom-repeater-field-page-navigation/
Thanks ractoon That’s a great help !
Feature request still stand as it would be nice to assign a unique palette to any color field by just using the color picker field options.
I’d have to agree with simchris.
If you’ve purchased the Pro version, I’m not sure how much support I’d expect for questions along the “How do I” line though.
For example, if it’s a question about something that’s really more about general WP then it is about ACF Pro those questions are probably not going to get an answer. When I visit here I do see a lot of questions that are more general WP questions than ACF specific questions.
Even when they are questions that are specific to how to do something with ACF, the documentation that’s available on this site is really good, and how to questions are likely to go unanswered by support, especially if it is something that’s covered in the documentation.
I don’t want to discount anyone that’s saying they’re having a problem getting answers from support, just saying that there may or may not be a valid reason why you’re not getting a response.
I do know that whenever I submit a bug report or when I’m asking about something that is not working the way I expect it to work that I generally get a reply within 24 hours.
Thanks for that! I did end up using something quite similar.
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.