In that case you would need to use string manipulation functions, or most likely regular expressions. The problem with these is that they may or may not work if the format of the content is altered
$value = get_sub_field('embed_iframe', false));
if (preg_match('/src="([^"]+)/', $value, $matches)) {
$url = $matches[1];
}
I think you would set 'default_value' => 0
. When I have questions like this I generally create a field like the type I want to use for my field with the settings I want it to have and then do an export to code to see that the settings are.
Even if this could be done in some way so that it would work with ACF image fields, there still would not be any way to prevent images being “removed in an over-enthusiastic cleanup.” WP uses the post_parent
in the _posts
table to mark an image uploaded to a post. WP has no built in mechanism for uploading or adding attachments to any other type of object. This is something that’s not likely to change, I doubt that you’ll ever see a built in WYSIWYG on a term or anywhere else in WP for that matter. Also, the post_parent
field requires an integer that is assumed to be another post ID, so anything created would be a work-a-round that would be outside of anything that WP would recognize.
There is one solution that I just thought of. There is the ability for ACF to save field values of options pages as related to a “post” (see the ‘post_id’ argument https://www.advancedcustomfields.com/resources/acf_add_options_page/) and I think that this will make it work the same, I just tested this and I know it works. The thing here is that you need posts, of some type, to store the values on and this means creating some type of post type for holding the options fields. My plugin that lets you create options pages using an admin interface will also let you save fields to the post of the options page settings… https://wordpress.org/plugins/options-page-admin-for-acf/
If you’re returning an image ID value then you need to get the URL of the image using https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/ as described under Basic display (ID) here https://www.advancedcustomfields.com/resources/image/
I would check out the first few results here https://www.google.com/search?q=php+allow+download+without+showing+link&ie=utf-8&oe=utf-8
Get the value of the field without formatting and supply the post ID of the post that you want to update. Get Field: https://www.advancedcustomfields.com/resources/get_field/; Update Field: https://www.advancedcustomfields.com/resources/update_field/
// $post_id is the ID of the post you want to update
// 3rd arg == false tells ACF not to format the value
// $users will == an array or user IDs
$users = get_field('user_field_name', $post_id, false);
// add the users ID to the array
$users[] = $new_user_id_to_add;
// update the field
// $selector == the field key of the field to update
update_field($selector, $users, $post_id);
Get the field value without formatting if this is an oembed field
<?php $value = get_sub_field('embed_iframe', false)); ?>
https://www.advancedcustomfields.com/resources/get_sub_field/
Uploaded to post is something that’s built into WP. The post ID is set as the parent of the attachment. There isn’t any way to do this for options pages or for that matter, terms in a taxonomy or any other object in WP.
I do not recall any topics ever being submitted here that included a solution for this.
I’m not even sure that it would be possible at all and I’m not sure where you’d start looking. The upload uses the built in WP file upload and works through AJAX. You might be able to add some filters during the process to detect that an attachment is being uploaded for a specific options page, then you could probably add a post meta field to the attachment to indicate what it was uploaded to, and finally you could probably filter the images that are being displayed during the AJAX call that shows these images to only show others that were uploaded for the same options page. However, this is all guess work, you’re probably looking at several hours of research and testing to get each part of this working, that is if it will work, and there’s no way of knowing until you try it.
ACF will need to be installed and active to use your plugin that uses ACF. There are couple ways to handle this. You can tell people that ACF is required or you can install ACF as part of your plugin https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/
You can’t repopulate the form.
Use an acf/validate_value filter for specific fields https://www.advancedcustomfields.com/resources/acf-validate_value/
For example, for the email field you can check existing email addresses. This will create an error message during the validation phase of the form.
This would only work for an ACF taxonomy field and not for the standard WP category meta box.
I don’t know if you can limit the categories in the WP meta box, after a quick search I found nothing on the subject. The only thing I can find information on is how to hide it.
Should have been more clear. I mean, where are the fields located? On an options page? On a product “post”. Since the “shop” page is a WC product archive page then you need to supply the post ID that the fields are saved to.
That really depends on how the other plugin adds these elements. I suspect that it will require some custom javascript or css or maybe some modification to the other plugin. In any case the best bet for finding out how to move them would be to ask the support team for that plugin.
You main shop page is a type of archive page, where are you trying to get this value from?
$post_object = get_field('select_sidebar');
Is it on a specific page/product? Is this inside of some type of a WP post loop while(have_posts)
?
The select field in ACF5 has a “Stylised UI” setting. This will not give the left/right drag feature, but it will retain the order of the selections made when getting the value of the field.
There isn’t anything for ACF that does exactly what you want, at least not that I know of.
Do you have any https://www.advancedcustomfields.com/resources/acf-validate_value/ filters on your site. This is where I’d look first for something that could cause this. An example of something that can easily cause this is not not returning $valid from the filter, for example
function my_validation_filter($valid, $value, $field, $input) {
// a statement like this will cause false validation failure
return;
// the above statement must look like this
return $valid;
}
You can use this filter https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-query/. See get terms arguments here https://developer.wordpress.org/reference/classes/wp_term_query/__construct/. You and use include to only list the ones you want or you can use exclude to eliminate the ones you don’t want.
The content field on the front end uses an ACF WYSIWYG field and not the standard WP field.
You might be about to alter the default value using an acf/prepare_field function… but this is only a guess and not tested, so I don’t know all of the details. https://www.advancedcustomfields.com/resources/acf-prepare_field/
add_filter('acf/prepare_field/name=_post_content', 'set_acf_form_default_content');
The value of the map field is stored as an array, which is serialzed for storage in the database.
I don’t know how your export works but converting to the old value might look something like
// $value holds value from the DB
$value = maybe_unserialize($value);
$value = $value['address'].'|'.$value['lat'].','.$value['lng'];
I don’t have a solution for reversing the order of flex fields.
You could possibly use a similar solution to https://support.advancedcustomfields.com/forums/topic/inverted-repeater/ by loading all of the flex field into an array and reversing, however, this would mean rewriting all of the code to use values from the array rather than using the normal ACF have_rows() and the_sub_field() functions.
There is a solution for making the collapsed fields easier to identify here https://www.advancedcustomfields.com/resources/acf-fields-flexible_content-layout_title/
A field type might be nice, but this is completely doable with the existing ACF fields and a filter or 2.
I would use a select field and https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/ using scandir http://php.net/manual/en/function.scandir.php to get the files to populate the field.
Then I would create a format value filter https://www.advancedcustomfields.com/resources/acf-format_value/ to convert the file name into a URL. But you could also set the value to the url when populating the choices.
$paths[] = get_stylesheet_directory().'/../KAWmaster/acf-json';
or
$paths[] = dirname(get_stylesheet_directory()).'/KAWmaster/acf-json';
k, so there’s an obvious typo in my code, proof that the brain sees what you expect to see since I missed it at least 4 times. Tell me if you can spot the difference
$args = array(
'post_type' => 'locations',
'posts_per_page' => -1
);
$query = new WP_Query($args);
$facebook_ids = array();
if ($query->have_posts()) {
while($query->have_posts()) {
$query->the_post();
echo get_field('facebook_group_name').'<br />';
$facebook_ids[] = get_field('facebook_group_name');
}
wp_reset_postdata();
}
echo implode(',', $facebook_ids);
well, that’s because I missed something extremely important
while ($the_query->have_posts()) {
$the_query->the_post(); // this is missing
// get state and compare it to the previous post
what kind of field is ‘facebook_group_name’ agian?
Then that shouldn’t be it.
What happens when you do this?
$args = array(
'post_type' => 'locations',
'posts_per_page' => -1
);
$query = new WP_Query($args);
$facebook_ids = array();
if ($query->have_posts()) {
while($query->have_post()) {
$query->the_post();
echo get_field('facebook_group_name').'<br />';
$facebook_ids[] = get_field('facebook_group_name');
}
wp_reset_postdata();
}
echo implode(',', $facebook_ids);
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.