Thank you for the ideas.
As for the first question, I’m thinking about moving all counties to one dropdown field. For the values I would use something like “martin_mn” with the label “Martin” to represent Martin County, Minnesota. With the combobox option enabled, I don’t think this would be a problem for data-entry, as the user can simply “search” for the county they want to select.
Hi James,
Thanks for your reply, but my question was regarding exporting fields.
When you do:
1. auto populate fields using example you shared
2. you export fields as php, so you can include them somewhere and you don’t have to re-create fields
you also get values exported for a select field you were auto populating.
Hi @eafarooqi,
From your code, you are hooking into the update_value function for a specific field and thus you cannot use the update_field() function within this function.
I would suggest you hook into the filter for every field or possibly use the update field() function for the other fields on their own.
Hi @alysko
Thank you for the feature request.
Kindly offer more details on your desired functionality for instance, would you like a search field to search other posts or to search the values contained in the acf_form?
This is great John, thank you for sharing. I’ll have a look and if I have any questions I’ll ping you on github. Many thanks again!
Hi @jrstaatsiii,
Thank you for sharing the solution. I will now copy the same to this forum so that it can help out a fellow dev in future:
<?php
/*
* Returns the first instance of a given layout option
* @param - $id - the id of the post you are trying to target: '' by default
* @param - $fc_field - the name of the ACF flexible field: 'content_blocks' as the default
* @param - $fc_layout - the name of the flexible content layout: 'visual_editor' as the default
* @return - mixed
* @todo - test different types of returned content. at the moment, I am only using this for returning a string
*/
function get_first_instance_of_content_block( $id = '', $fc_field = 'content_blocks', $fc_layout = 'visual_editor' ) {
if ( class_exists('acf') ) {
if ( have_rows( $fc_field, $id ) ) {
$content_blocks = get_field( $fc_field, $id );
$content = array();
foreach ( $content_blocks as $block ) {
if ( $block['acf_fc_layout'] == $fc_layout ) {
$content[] = $block[$fc_layout];
}
}
reset($content);
return $content[0];
}
} else {
return '<p class="error">Advanced Custom Fields is required for <code>get_first_instance_of_content_block()</code> to work.</p>';
}
}
Hi @chriswhiteley,
You can make use of the the WP_Query object to load all the posts ordered by a custom field in your case based on the last_name field:
The code will look something like this:
<?php
// query
$the_query = new WP_Query(array(
'post_type' => 'post_type_name',
'posts_per_page' => -1,
'meta_key' => 'last_name',
'orderby' => 'meta_value_num',
'order' => 'ASC'
));
?>
Hi @solserpiente,
The conversion of text inputs to pst tags would only work for single value custom fields in which case you would need the following JQuery function for the implementation(it should go to your functions.php file):
<?php
function convert_custom_fields_to_tags(){ ?>
<script type="text/javascript">
jQuery(document).ready(function($){
// Create list of custom fields to add as tags on save
// (e.g. var custom_field_names = ['my_custom_field', 'my_other_custom_field', 'yet_another_custom_field'];)
var custom_field_names = [];
$('form#post').submit(function(){
if(custom_field_names.length > 0) {
var custom_field_values = [];
$('#postcustom tr[id^="meta-"]').each(function(){
var meta_id = $(this).attr('id').substring($(this).attr('id').indexOf('-')).replace('-','');
if ($.inArray($(':text[id="meta[' + meta_id + '][key]"]').val(), custom_field_names) !== -1) {
custom_field_values.push($('textarea[id="meta[' + meta_id + '][value]"]').val().toLowerCase());
}
});
var tags = custom_field_values.join(',');
$('#new-tag-post_tag').val(tags);
}
});
});
</script>
<?php }
add_action('admin_footer', 'convert_custom_fields_to_tags');
?>
You would then need to add the custom field names to the custom_field_names array as follows:
var custom_field_names = ['my_custom_field', 'my_other_custom_field'];
Hi @fireundubh,
Thank you for the recommendation.
This feature request has been added to the developer’s to do list and hopefully it will see its way in to the plugin in the near future.
Have a good one!
Hi @tkajergaard,
Thank you for the submission.
This request has been dispatched to the developer and hopefully it will be integrated in to the plugin in the near future.
Did you have any luck with creating the filter?
Hi @brunocloutier,
You can make use of the acf/fields/post)object/query filter to change the order of the posts queried by the WP_Query function and thus change the posts displayed by the field.
I would recommend you modify the $args array and change the ‘order_by’ value to ‘ID’ or ‘author’
The code should look like this:
<?php
function my_post_object_query( $args, $field, $post )
{
// modify the order
$args['orderby'] = 'ID';
return $args;
}
// filter for every field
add_filter('acf/fields/post_object/query', 'my_post_object_query', 10, 3);
Hi @lletnek,
Thank you for the submission of the feature request, this would really make a nice addition to the plugin.
I have sent this information to the developer for consideration and hopefully this will see its way into the plugin in the near future.
Hi @oppodeldoc
The get_field_objects() function would not work in this scenario since you are trying to query some term objects.
I would recommend you make use of a for each loop to get the terms as shown below:
<?php
$terms = get_field('taxonomy_field_name');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<h2><?php echo $term->name; ?></h2>
<p><?php echo $term->description; ?></p>
<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Hi @jursdotme
Thank you for the great description of the issue, the feature request has been received and has been sent forth to the developer 🙂
This would really make a great addition to the plugin!
Hi @sascha
Thank you for the feature request. Information about this has been forwarded to the developer and hopefully this will see its way in to the plugin in the near feature.
Hi @pilgrimish
It looks like the last query in your code is the one which is related to your question, is this correct?
Within this ‘client’ loop, you will need to use the get_posts
function to see if any posts exist (‘work’) which contain a custom field value where the current ‘client’ has been selected.
Is all the rest of your code working?
If so, the additional get_posts should be quite straight forward. Please read over the doc to understand how you can use compare LIKE to find a value within a serialized array.
Thanks
E
Hi @keliix06
Thanks for the bug report.
It may be possible that due to the button having a title attribute, the button may need to be clicked twice, can you please remove your extra code and try this first?
There should be a solution for this that does not require an extra touchstart action for every field JS.
Thanks
E
$query->set('posts_per_page', -1);
should be correct.
Sorting by 2 meta field, until quite recently was not really possible, or at best difficult. However, WP 4.2 introduced and improvement that will allow this. See this: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/
You can call acf_get_fields() using the field_group key, for example: $fields = get_fields('group_5570c274a5741');
This will return a multidimensional array. You could then look through the array to find all fields of a specific type.
I doubt this would cause any performance issues. This information is cached by ACF so that they will not be re-queried.
The question is not really an ACF question but a WP/TniyMCE question.
Here is a good article: https://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
you can find more info by doing a google search for “altering allowed html elements in wp tinymce”
Not sure if you still need help with this, trying to clear up some older questions.
If I understand correctly, on you site the “post” post type has a custom field on it that is named “drivers” and this field is a relationship field.
If this is true then what you have should work. The only thing I can come up with looking at your code is that you’re either querying the wrong post type or that the field name is not “drivers”
I’m only guessing, but the reason this is not a feature is because different people would want to see different things, and the list of what could be shown is quite large: order, group key, location rules, what’s hidden on the screen, position, style. Each person may want different things depending on their own preferences and needs.
Add this to functions.php and it will add the order value to the list.
function acf_field_group_columns($columns) {
$columns['menu_order'] = __('Order');
return $columns;
} // end function reference_columns
add_filter('manage_edit-acf-field-group_columns', 'acf_field_group_columns', 20);
function acf_field_group_columns_content($column, $post_id) {
switch ($column) {
case 'menu_order':
global $post;
echo '<strong>',$post->menu_order,'</strong>';
break;
default:
break;
} // end switch
} // end function reference_columns_content
add_action('manage_acf-field-group_posts_custom_column', 'acf_field_group_columns_content', 20, 2);
heh, yes, I had originally thought of making this some type of plugin, but the thought of maintaining it turned me off. It is mostly a plugin but not anything that is fit for public consumption.
First so you know what you’re looking at, I don’t use jQuery, the script that does the replacement is actually quite small and efficient.
A little background about the ACF fields. In my ACF field group I have a radio button. The user can select to upload a single image and use WP auto resized images or they can choose to upload a different image for each size. The image widths that are used are 320, 640, 768, 1024 and 1280. The image fields displayed for upload are all conditional fields depending on what is selected. All of the sizes have WP image sizes created for them like.
add_image_size('image-size-name', $width, 9999);
In the PHP I get the fields, based on what the user has selected, get the right image urls and generate an tag that is used by picturefill.js
I put a copy of it on this repo, it is the only thing currently there
https://github.com/Hube2/blunt-panes
If you have any questions about the JS I’d be glad to answer them over on the issue section for that repo so we don’t fill up this thread with something that is really not related to ACF.
New code mixed into yours and commented
<?php
$images = get_field('photo_gallery','17');
if( $images ):
shuffle($images); // randomizes the image array
$max = 10; // set the max here;
$count = 0; // current count
?>
<ul>
<?php
foreach( $images as $image ):
$count++; // increment count
// if count is greater than limt, stop showing images
if ($count > $max) {
break;
}
?>
<li>
<a href="<?php echo $image['url']; ?>" rel="lightbox">
<img src="<?php echo $image['sizes']['photo-gallery']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
</li>
<?php endforeach; ?>
<div id="clearfloat"></div>
</ul>
<?php endif; ?>
In most cases it would be much easier to alter the code in your template to check for a value an if it does not exist then show the default.
$value = get_field('my_field');
if ($value === false) {
$value = 'default_value';
}
To do it the other way, you can:
I generally do the former and code my templates to deal with default values because I assume that any field might be empty.
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.