skip to Main Content

I have a custom checkbox field created in WordPress where the user can select various facilities available at a listed property.

I am building a page template using Elementor.

When I import the data from ACF, it displays as a comma separated list.

Is there any way I can instead get this to display as as a bulleted list?

3

Answers


  1. Here is a code to get the output data from ACF as a bulleted list –

    <?php
        $arr = get_the_field('field_name');
        $str = explode (",", $arr);
        echo '<ul>';
        foreach($str as $s){
            echo '<li>'.$s.'</li>';
        }
        echo '</ul>';
    ?>
    

    I hope this is what you are looking for.

    Login or Signup to reply.
  2. You could try using a plugin that let’s you create php code snippets and run them with a shortcode such as this: https://it.wordpress.org/plugins/insert-php/

    Once you created the php snippet you could try to run it with a shortcode using Elementor’s shortcode widget.

    Login or Signup to reply.
  3. I’d slightly adjust Tahmid’s excellent answer. In order to allow for empty lines (without a bullet) use this in you functions.php file:

    /**
     * create a ACF text field with bullets
     * Empty lines stay empty
     * @param string $field_name Name of the field to bullet
     */
    function acf_bullets(string $field_name): void {
        $format_acf_bullet = function(
            string $value,
            int $post_id,
            array $form ):string {
            if( empty($value) ) {
                return '';
            }
            $lines = explode( "n", $value );
            $result = "<ul class="theme-ul">n";
            foreach( $lines as $line) {
                if( strlen($line)<=1 ) { // empty line, start a new list
                    $result .= "</ul><p/><ul class="theme-ul">n";
                } else {
                    $result .= "<li>".$line."n";
                }
            }
            $result .= "</ul>n";
            return $result;
        };
        add_filter("acf/format_value/name=$field_name", $format_acf_bullet, 10, 3);
    }
    

    Call this with acf_bullets('your-fieldname-here');

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search