Home › Forums › General Issues › Checkbox Field, Commas, Shortcode for get_field? › Reply To: Checkbox Field, Commas, Shortcode for get_field?
I created the following shortcode for you [acfBr field="FIELD_NAME"]
. This will get the field and replace all the commas with <br> tags before it returns the result.
Paste the following code at the bottom of your functions.php document in your theme folder.
add_shortcode('acfBr', 'brListFunction');
public function brListFunction($atts, $content) {
extract(shortcode_atts(array("id"=>'','field'=>''),$atts));
if($field){
if($id=''){
global $post;
$id=$post->ID;
}
$content=get_field($field,$id);
return str_replace(',','<br>',$content);
}
return '';
}
This shortcode was created just for your lists and may not work correctly for all your other fields. If you have any issues please let me know.
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.