Home › Forums › General Issues › Need help with creating new field type with ACF › Reply To: Need help with creating new field type with ACF
I’m sure that a lot of thing missing from my field to work, but i have no idea what.
Here is my hole field:
<?php
class acf_field_year_n_text extends acf_field{
var $settings,
$defaults;
function __construct(){
$this->name = 'year_n_text';
$this->label = __('Year and text');
$this->category = __("Content",'acf');
$this->defaults = array(
'default_value' => '',
'formatting' => 'br',
);
parent::__construct();
$this->settings = array(
'path' => apply_filters('acf/helpers/get_path', __FILE__),
'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
'version' => '1.0.0'
);
}
function create_options($field){
$key = $field['name'];
?>
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php _e("Formatting",'acf'); ?></label>
<p class="description"><?php _e("Define how to render html tags",'acf'); ?></p>
</td>
<td>
<?php
do_action('acf/create_field', array(
'type' => 'select',
'name' => 'fields['.$key.'][formatting]',
'name2' => 'fields['.$key.'2][formatting]',
'value' => $field['formatting'],
'choices' => array(
'none' => __("None",'acf'),
'br' => __("auto <br />",'acf'),
'html' => __("HTML",'acf'),
)
));
?>
</td>
</tr>
<?php
}
function create_field( $field ){
?>
<table >
<tr>
<th scope="col">Year</th>
<th scope="col">Text</th>
</tr>
<tr>
<?php var_dump ($field['value']); ?>
<td>
<?php echo '<textarea
id="' . $field['id'] . '"
rows="4"
class="' . $field['class'] . '"
name="' . $field['name']['textarea_1'] . '" >'
. $field['value']['textarea_1'] .
'</textarea>';
?>
</td>
<td>
<?php echo '<textarea
id="' . $field['id'] . '"
rows="4"
class="' . $field['class'] . '"
name="' . $field['name']['textarea_2'] . '" >'
. $field['value']['textarea_2'] .
'</textarea>';
?>
</td>
</tr>
</table>
<?php
}
function input_admin_enqueue_scripts(){
wp_register_script('acf-input-year_n_text', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version']);
wp_register_style('acf-input-year_n_text', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version']);
wp_enqueue_script(array(
'acf-input-year_n_text',
));
wp_enqueue_style(array(
'acf-input-year_n_text',
));
}
}
new acf_field_year_n_text();
?>
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.