You could use ACF’s built-in form functionality (see: http://www.advancedcustomfields.com/resources/tutorials/creating-a-front-end-form/). If you want more fine-grained control, I know others have used ACF with Front End Edit (https://github.com/scribu/wp-front-end-editor), which is probably the most popular and stable plug-in for inline editing.
You could also try a plug-in I’ve been developing, X-Editable-ACF (https://github.com/wells5609/X-Editable-ACF). I can almost guarantee you’ll run into bugs or something that doesn’t work, but its worth a look if you’re comfortable with PHP.
I see two ways of doing this:
1. Rather than using PHP to write directly to CSS files (which could cause cache issues), you could generate separate <style> tags for the media rules and insert these in the <head>. For example:
<style media="screen and (max-width: 800px)">
// CSS
</style>
2. You could create a PHP script to dynamically create a concatenated CSS file. Chris Coyer’s site WP-Mix has a good code snippet to get you started: http://wp-mix.com/combine-compress-css-files-php/
To get the URL from an attachment ID you can use:
<?php wp_get_attachment_image_src( $attachment_id, $size, $icon ); ?>
where $size (str|array) and $icon (bool) are optional.
The “real” answer: go to the Field Group admin page, click the “display field key” button in help dropdown, then copy & paste the key into code.
Maybe closer to the answer you’re looking for:
function acf_field_key($field_name, $post_id = false){
if ( $post_id )
return get_field_reference($field_name, $post_id);
if( !empty($GLOBALS['acf_register_field_group']) ) {
foreach( $GLOBALS['acf_register_field_group'] as $acf ) :
foreach($acf['fields'] as $field) :
if ( $field_name === $field['name'] )
return $field['key'];
endforeach;
endforeach;
}
return $field_name;
}
However, this only works for fields registered with PHP via register_field_group().
A few ACF-ers (myself included) have had luck with this plugin: http://wordpress.org/plugins/csv-importer/
I think the issue is that you’re trying to reference a variable in single-event.php ($instructor_organization) which is defined in functions.php – this is because the variable is “out of scope” (see: http://php.net/manual/en/language.variables.scope.php).
You’ll need something like this in single-event.php:
the_field('instructor_organization');
// OR
echo get_field('instructor_organization');
Both output the field value. Alternatively, you could do:
// in functions.php:
function get_instructor_org($post_id){
$org = get_field('instructor_organization', $post_id);
return $org;
}
// then in single-event.php:
// assuming you're in the Loop (i.e. $post variable is available)
echo get_instructor_org($post->ID);
Obviously the first way is easier, but the second gives you an idea of how variables can be passed to functions.
I will attempt to answer the first question. ACF uses two types of field names in order to associate the field with its object; as you see in the postmeta table of your DB, only the value is saved (in “meta_value”) for the posts’ field name (in “meta_key”). So, in order to access the rest of the field object (e.g. “label”, “format”, “type”, “choices”, etc.), ACF must be able to look this up using a unique identifier (the key). This ensures that post meta is stored the way same as (and hence, compatible with) native WP meta. So, when ACF gets a field, it looks for the meta_key with the same name as the requested field but prefixed with an underscore – this gives it the key that allows it to find the rest of the object.
You could use the current page’s ‘post_parent’ field as the argument for get_ancestors() to ascend the page hierarchy:
global $post;
$parent = $post->post_parent;
$grandparents = get_ancestors( $parent, 'page');
$country = get_field( 'country', $grandparents[0] );
Haven’t tested this but should work
Try this:
list($day, $month, $year) = sscanf('12/04/2010', '%02d/%02d/%04d'); // field value
$datetime = new DateTime("$year-$month-$day"); // your format
echo $datetime->format('r'); // desired format
source: http://stackoverflow.com/questions/2621433/date-create-from-format-equivalent-for-php-5-2-or-lower
Assuming you’re using this in the ‘register_field_group()’ function? What is your field group setting(s)? Is the data saving to the database correctly?
EDIT: I think I read your question wrong (or too quickly).
ACF won’t automatically recognize a custom save_format – you’ll have to add this in yourself via a custom field type. I would take a look at the textarea field class and modify the ‘format_value_for_api()’ method (in your custom field type class).
Does the user-role you’re logged in as have the ‘manage_options’ capability?
What version of WordPress and ACF are you running?
Try using meta_query and specifying ‘type’ => ‘DATE’. Or you could try using “meta_value_num” as the ‘orderby’ argument, but I can’t remember if this works or not. See: http://codex.wordpress.org/wp_query#Custom_Field_Parameters
Was ACF updated as well? If so, what was/is the version number prior and current? What other plugins are installed? Are you getting javascript errors on those non-functioning pages?
Wow, fast response there
Yes, I believe user custom fields do not get meta boxes.
Do you have the correct location permissions? i.e. if you set the field to display for users of type x, are you logged in as that type?
Also, are you getting any javascript errors? (the custom fields are rendered via JS)
I believe this is the Settings API referred to: http://codex.wordpress.org/Settings_API
Mike, I’d love to see the icon field when you’re ready – are you using FontAwesome by chance?
I’ll echo the suggestion for creating custom field types – it’s actually much simpler than initially seems. In my opinion, ACF development (i.e. Elliot) should focus on improving core rather than adding new features which would likely not be used by all (though I am not trying to direct Elliot’s efforts, nor am I discounting the suggestions above). The image radio field is an interesting idea though.
Try using get_field_objects() including the (user) ID, as in:
$user_meta = get_field_objects('user_' . $userID);
foreach($user_meta as $meta) :
if (strpos($meta['name'], 'user_q_') !== FALSE) { ?>
<h3><?php echo $meta['label']; ?></h3>
<div><?php echo $meta['value']; ?></div>
<?php }
endforeach;
Notice the field key is returning the field’s name prefixed with “field_” – this means ACF can’t find the actual field object for the post (but it can find the meta_value).
You can also hook into “acf/register_fields”, although I’m not sure of the benefits or downsides to either approach.
Another self-taught chiming in…
Building on Jonathan’s example, I would create a separate template for company post archives. Then you would just change the get_template_part function call to get_template_part( ‘content’,’company-posts’ ); or similar, and skip the “if($_GET)” validation stuff.
A bit strange you’re being directed to ../companies/ if your post-type slug is ‘company’ since archives aren’t automatically pluralized.
Lastly, what error are you getting?
I’m liking your use of classes for fields, which got me thinking about an abstracted static class for performing similar look-ups & related tasks.
Using the function posted above, however, you could eliminate the required cut-and-paste:
update_field( get_acf_field_key('registration_number'), $registration_number, $postID);
@elliot – any interest in including something like this in core? Any suggestions?
If you want the field value from just 1 post, you could enter 510 as the second argument like:
$field = get_field('link', 510);
echo $field;
// etc...
This should work regardless of where the code is placed.
Call register_field_group on “init”
I think what Jonathan was getting at is that it’s not helpful for other users looking for the solution. To your point, it wouldn’t be difficult to find the solution in this case, but it could be for threads with multiple replies; so in principle, its probably not a good practice.
Here’s a function which grabs the field key from registered field groups given a name (note it returns the first key found, so it won’t work with multiple fields with the same name):
function get_acf_field_key($name) {
if( !empty($GLOBALS['acf_register_field_group']) ) {
foreach( $GLOBALS['acf_register_field_group'] as $acf ) {
foreach($acf['fields'] as $field) :
if ( $name === $field['name'] ) {
return $field['key'];
}
endforeach;
}
}
}
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.