Support

Account

Home Forums Search Search Results for 'Wysiwyg'

Search Results for 'Wysiwyg'

topic

  • Helping

    Code – HTML – Script field for Hubspot form

    Hello there,
    I am building out a site and have ACF Pro. I am working on a field group that requires a Hubspot form to be placed on individual custom post types.
    For example – Events Field Group
    Event Title
    Event description
    Event speakers
    Hubspot form code.

    There is a different Hubspot form for each event and the Admin needs to enter this code in the Custom Post Type Events, to keep them from messing with the Elemntor template created specifically for Events. Normally I would just create individual event pages that are cloned from a master, but the client wants to have the events as a Loop.

    Can this be done – A field for this code? I have tried the WYSIWYG and have tried the Text area with no formatting, but nothing seems to work.
    ANY help is greatly appreciated.

  • Unread

    Wysiwyg Editor field to product category

    Hi,
    I have added a Wysiwyg Editor field to product category. I am using astra theme. But this ACF field content is not showing in the front end. How can I show this in the front. Can you please help me?

  • Unread

    Can I have 3 fields of custom code under one field of heading?

    Hi All
    I am using:
    Advanced Custom Fields
    Elementor Pro
    Lifter Elements
    Lifter LMS
    Astra Theme
    I just watch this amazing tutorial https://www.youtube.com/watch?v=oSaDk9-GHJ8 and it is exactly what I need.
    I want to put 3 links underneath each lesson video (as per my image).
    My questions are:
    Do I need to do the step with the Wysiwyg editor from this youtube video? Is that step required to create a space for the short code?
    Can anyone advise how to set it up in Advanced Custom Fields: I want there to be one heading of “Support lessons Required” with a few support videos under it. I do not want it to repeat the heading “Support lessons” for each custom field of each link.
    Thank you

  • Helping

    Display Fields corectly based on Coditions

    Hi guys i am developing a plugin for my own purpose nothing commercial, it’s just a way to automate my future work and I am facing something peculiar, I admit I am not using the latest version of ACF because I am developing on localhost, I am not willing to use my licence on a localhost environment.
    So this is not necessary a technical issue, I mean is something between frontend a backend, I admit I am able to fix this somehow but I need to know if there is a propper method to do it:

    I have a big repeater field and there are conditions all around it, when it comes to display fields based on these conditions, will mess things around, spacings, etc.

    this is the json Fields :

    
    acf_add_local_field_group(array(
            'key' => 'group_66125eef10578',
            'title' => 'Slideshow',
            'fields' => array(
                array(
                    'key' => 'field_6614259e8d6f3',
                    'label' => 'Slideshow',
                    'name' => '',
                    'type' => 'tab',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'placement' => 'top',
                    'endpoint' => 0,
                ),
                array(
                    'key' => 'field_661435860c17d',
                    'label' => 'Slideshow Post type',
                    'name' => 'slideshow_post_type',
                    'type' => 'select',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'choices' => array(
                        'multimedia' => 'Multimedia',
                        'products' => 'Products',
                        'gallery' => 'Gallery',
                        'posts' => 'Posts / Pages / Custom CTPS',
                    ),
                    'default_value' => false,
                    'allow_null' => 0,
                    'multiple' => 0,
                    'ui' => 0,
                    'return_format' => 'value',
                    'ajax' => 0,
                    'placeholder' => '',
                ),
                array(
                    'key' => 'field_66125ef55e8f9',
                    'label' => 'Slides',
                    'name' => 'slideshows',
                    'type' => 'repeater',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => array(
                        array(
                            array(
                                'field' => 'field_661435860c17d',
                                'operator' => '==',
                                'value' => 'multimedia',
                            ),
                        ),
                    ),
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'collapsed' => '',
                    'min' => 0,
                    'max' => 0,
                    'layout' => 'table',
                    'button_label' => '',
                    'sub_fields' => array(
                        array(
                            'key' => 'field_66125f765e8fa',
                            'label' => 'Slide Type',
                            'name' => 'slide_type',
                            'type' => 'select',
                            'instructions' => 'Select the type of the slide you want to display',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'choices' => array(
                                'image' => 'Only Image',
                                'video' => 'Only Video',
                                'custom' => 'Custom Slide',
                            ),
                            'default_value' => false,
                            'allow_null' => 0,
                            'multiple' => 0,
                            'ui' => 0,
                            'return_format' => 'value',
                            'ajax' => 0,
                            'placeholder' => '',
                        ),
                        array(
                            'key' => 'field_6612a963f9b30',
                            'label' => 'Slide Custom Background',
                            'name' => 'slide_custom_background',
                            'type' => 'select',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => array(
                                array(
                                    array(
                                        'field' => 'field_66125f765e8fa',
                                        'operator' => '==',
                                        'value' => 'custom',
                                    ),
                                ),
                            ),
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'choices' => array(
                                'image' => 'Image background',
                                'video' => 'Video background',
                            ),
                            'default_value' => false,
                            'allow_null' => 0,
                            'multiple' => 0,
                            'ui' => 0,
                            'return_format' => 'value',
                            'ajax' => 0,
                            'placeholder' => '',
                        ),
                        array(
                            'key' => 'field_6614add9153df',
                            'label' => 'Apply overlay',
                            'name' => 'apply_overlay',
                            'type' => 'true_false',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'message' => '',
                            'default_value' => 0,
                            'ui' => 0,
                            'ui_on_text' => '',
                            'ui_off_text' => '',
                        ),
                        array(
                            'key' => 'field_6614adfb153e0',
                            'label' => 'Overlay color',
                            'name' => 'overlay_color',
                            'type' => 'color_picker',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => array(
                                array(
                                    array(
                                        'field' => 'field_6614add9153df',
                                        'operator' => '==',
                                        'value' => '1',
                                    ),
                                ),
                            ),
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'enable_opacity' => 1,
                            'return_format' => 'string',
                        ),
                        array(
                            'key' => 'field_661260ac186f8',
                            'label' => 'Slide Image',
                            'name' => 'slide_image',
                            'type' => 'image',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => array(
                                array(
                                    array(
                                        'field' => 'field_66125f765e8fa',
                                        'operator' => '==',
                                        'value' => 'image',
                                    ),
                                ),
                                array(
                                    array(
                                        'field' => 'field_66125f765e8fa',
                                        'operator' => '==',
                                        'value' => 'custom',
                                    ),
                                ),
                                array(
                                    array(
                                        'field' => 'field_6612a963f9b30',
                                        'operator' => '==',
                                        'value' => 'image',
                                    ),
                                ),
                            ),
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'return_format' => 'array',
                            'preview_size' => 'medium',
                            'library' => 'all',
                            'min_width' => '',
                            'min_height' => '',
                            'min_size' => '',
                            'max_width' => '',
                            'max_height' => '',
                            'max_size' => '',
                            'mime_types' => '',
                        ),
                        array(
                            'key' => 'field_6612a83ca59b6',
                            'label' => 'Slideshow Video',
                            'name' => 'slideshow_video',
                            'type' => 'url',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => array(
                                array(
                                    array(
                                        'field' => 'field_66125f765e8fa',
                                        'operator' => '==',
                                        'value' => 'video',
                                    ),
                                ),
                                array(
                                    array(
                                        'field' => 'field_6612a963f9b30',
                                        'operator' => '==',
                                        'value' => 'video',
                                    ),
                                ),
                            ),
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'placeholder' => '',
                        ),
                        array(
                            'key' => 'field_6612a74c96a57',
                            'label' => 'Slideshow Text',
                            'name' => 'slideshow_text',
                            'type' => 'wysiwyg',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => array(
                                array(
                                    array(
                                        'field' => 'field_66125f765e8fa',
                                        'operator' => '==',
                                        'value' => 'custom',
                                    ),
                                ),
                            ),
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'tabs' => 'all',
                            'toolbar' => 'full',
                            'media_upload' => 1,
                            'delay' => 0,
                        ),
                        array(
                            'key' => 'field_6612a76a96a58',
                            'label' => 'Slideshow Text orientation',
                            'name' => 'slideshow_text_orientation',
                            'type' => 'select',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => array(
                                array(
                                    array(
                                        'field' => 'field_66125f765e8fa',
                                        'operator' => '==',
                                        'value' => 'custom',
                                    ),
                                ),
                            ),
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'choices' => array(
                                'left' => 'Align Left',
                                'right' => 'Align Right',
                                'center' => 'Align Center',
                            ),
                            'default_value' => false,
                            'allow_null' => 0,
                            'multiple' => 0,
                            'ui' => 0,
                            'return_format' => 'value',
                            'ajax' => 0,
                            'placeholder' => '',
                        ),
                        array(
                            'key' => 'field_6614277a8d6fa',
                            'label' => 'Slideshow interval',
                            'name' => 'slideshow_interval',
                            'type' => 'number',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '20',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'placeholder' => '',
                            'prepend' => '',
                            'append' => '',
                            'min' => '',
                            'max' => '',
                            'step' => '',
                        ),
                    ),
                ),
                array(
                    'key' => 'field_6614b1ec5fc8f',
                    'label' => 'Gallery Slides',
                    'name' => 'gallery_slides',
                    'type' => 'gallery',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => array(
                        array(
                            array(
                                'field' => 'field_661435860c17d',
                                'operator' => '==',
                                'value' => 'gallery',
                            ),
                        ),
                    ),
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'return_format' => 'array',
                    'preview_size' => 'medium',
                    'insert' => 'append',
                    'library' => 'all',
                    'min' => '',
                    'max' => '',
                    'min_width' => '',
                    'min_height' => '',
                    'min_size' => '',
                    'max_width' => '',
                    'max_height' => '',
                    'max_size' => '',
                    'mime_types' => '',
                ),
                array(
                    'key' => 'field_661425b48d6f4',
                    'label' => 'Options',
                    'name' => '',
                    'type' => 'tab',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'placement' => 'top',
                    'endpoint' => 0,
                ),
                array(
                    'key' => 'field_661425d48d6f5',
                    'label' => 'Slideshow Height',
                    'name' => 'slideshow_height',
                    'type' => 'select',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '33.3',
                        'class' => '',
                        'id' => '',
                    ),
                    'choices' => array(
                        'px' => 'Pixels',
                        'vh' => 'View Port Height',
                    ),
                    'default_value' => false,
                    'allow_null' => 0,
                    'multiple' => 0,
                    'ui' => 0,
                    'return_format' => 'value',
                    'ajax' => 0,
                    'placeholder' => '',
                ),
                array(
                    'key' => 'field_661426208d6f6',
                    'label' => 'Height Number',
                    'name' => 'height_number',
                    'type' => 'number',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '33.3',
                        'class' => '',
                        'id' => '',
                    ),
                    'default_value' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                    'min' => '',
                    'max' => '',
                    'step' => '',
                ),
                array(
                    'key' => 'field_6614ad39baef8',
                    'label' => 'Inherit theme colors',
                    'name' => 'inherit_theme_colors',
                    'type' => 'true_false',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '33.3',
                        'class' => '',
                        'id' => '',
                    ),
                    'message' => '',
                    'default_value' => 0,
                    'ui' => 0,
                    'ui_on_text' => '',
                    'ui_off_text' => '',
                ),
                array(
                    'key' => 'field_6614264e8d6f7',
                    'label' => 'Display Arrows',
                    'name' => 'display_arrows',
                    'type' => 'true_false',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '33.3',
                        'class' => '',
                        'id' => '',
                    ),
                    'message' => '',
                    'default_value' => 0,
                    'ui' => 0,
                    'ui_on_text' => '',
                    'ui_off_text' => '',
                ),
                array(
                    'key' => 'field_6614acf4baef6',
                    'label' => 'Arrow Color',
                    'name' => 'arrow_color',
                    'type' => 'color_picker',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => array(
                        array(
                            array(
                                'field' => 'field_6614ad39baef8',
                                'operator' => '!=',
                                'value' => '1',
                            ),
                        ),
                    ),
                    'wrapper' => array(
                        'width' => '33.3',
                        'class' => '',
                        'id' => '',
                    ),
                    'default_value' => '',
                    'enable_opacity' => 1,
                    'return_format' => 'string',
                ),
                array(
                    'key' => 'field_661426618d6f8',
                    'label' => 'Display Indicator',
                    'name' => 'display_indicator',
                    'type' => 'true_false',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '33.3',
                        'class' => '',
                        'id' => '',
                    ),
                    'message' => '',
                    'default_value' => 0,
                    'ui' => 0,
                    'ui_on_text' => '',
                    'ui_off_text' => '',
                ),
                array(
                    'key' => 'field_6614ad1bbaef7',
                    'label' => 'Indicators color',
                    'name' => 'indicators_color',
                    'type' => 'color_picker',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => array(
                        array(
                            array(
                                'field' => 'field_6614ad39baef8',
                                'operator' => '!=',
                                'value' => '1',
                            ),
                        ),
                    ),
                    'wrapper' => array(
                        'width' => '33.3',
                        'class' => '',
                        'id' => '',
                    ),
                    'default_value' => '',
                    'enable_opacity' => 1,
                    'return_format' => 'string',
                ),
                array(
                    'key' => 'field_661426ca8d6f9',
                    'label' => 'Slideshow Sliding Effect',
                    'name' => 'slideshow_sliding_effect',
                    'type' => 'select',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '33.3',
                        'class' => '',
                        'id' => '',
                    ),
                    'choices' => array(
                        'normal' => 'Normal Slide / Swipe',
                        'fade' => 'Fade in Slide',
                    ),
                    'default_value' => false,
                    'allow_null' => 0,
                    'multiple' => 0,
                    'ui' => 0,
                    'return_format' => 'value',
                    'ajax' => 0,
                    'placeholder' => '',
                ),
            ),
            'location' => array(
                array(
                    array(
                        'param' => 'post_type',
                        'operator' => '==',
                        'value' => 'evx_slideshow',
                    ),
                ),
            ),
            'menu_order' => 0,
            'position' => 'normal',
            'style' => 'default',
            'label_placement' => 'top',
            'instruction_placement' => 'label',
            'hide_on_screen' => '',
            'active' => true,
            'description' => '',
            'show_in_rest' => 0,
        ));
    
    endif;
    

    This is the image with the mess it brings :
    Check this out

    In advance, i don’t need to help me developing a solution, i just need to know if there is something you guys know how to easy deal with or if i mistake something in my implementation of displaying these fields.
    Cheers, Lucian.

  • Solving

    Stop oEmbed in Basic WYSIWYG

    Does anyone have a good way to completely stop oEmbed like pasting in a YouTube URL from working in the Basic WYSIWYG fields?

    I know I could filter it out on the front end, but I want to stop it from working at all on the backed so editor users don’t get the impression that’s something they can do.

    We would want it to keep working for “Full” WYSIWYG fields, but the places we implement the “Basic” WYSIWYG we’re trying to just offer bold, italics, links and that’s all.

  • Unread

    How to initialize TinyMCE with Javascript?

    I have a repeater with a acf-field-wysiwyg with “Delay initialization” activated.
    I would like to initialize TinyMCE with JS, not by clicking on the editor itself. I tried everything but I do not manage to achieve it.

    I even asked ChatGPT, who suggested the following, but no success :

    $('.acf-field-wysiwyg').each(function() {
    var field = $(this),
    editor = field.find('.acf-editor-wrap');

    // Check if the editor exists and if it has not been initialized already
    if (editor.length && !editor.hasClass('tmce-active')) {
    // Trigger the ACF action to initialize TinyMCE
    field.trigger('acf/setup_fields', [editor]);
    }
    });

    field.find(‘.acf-editor-wrap’); doesn’t seem correct but i tried a lot of different targets and still no success.

  • Unread

    Need edit help ACF – i can’t edit

    Hello

    I took over the support of a non profit website that was built by someone else and the content is mostly created through ACF field groups. i can update some regular pages directly by the admin pages/post.

    Im not sure if this is related to the escaping html change, but i can’t seem to be able to edit anything using the ACF tools/panel and nothing in pages either.
    when i look in the corresponding template pages in PHP, i can see the section as: <?php the_field(‘prices_heading’); ?> and other like <?php the_field(‘prices_content’); ?>

    the site itself is working but the content/text needs to be updated. so far i can’t find any text.

    the WYSIWYG editor does not offer any edit capability. i looked in the DB but not sure if the text is saved somewhere.

    If i disable ACF, the full site goes broken.

    i dont need to update the design/layout, just the text.

    Ideas?

  • Solving

    Escape HTML without editing PHP

    I am trying to support a client whose site I did not build, where almost all content is created through ACF field groups. They have a predicatable issue with the recent escaping html change, where an embedded form from a third-party vendor that was inserted into a WYSIWYG field is no longer displaying.

    I need to add the escape html instruction to this field, but can’t figure out where to add it. I don’t see a setting in the ACF Field Groups interface where the WYSIWYG field is made available for use in the page template.

    If there isn’t a way to resolve this in the ACF plugin UI, I do have access to edit the template files, so am open to suggestions there too.

    Thanks

  • Helping

    Repeaters – Get Sub-Field Siblings

    Hi 🙂

    So, I’m trying to use ACF Repeater fields to make a rudimentary translation system but I’m failing on something that feels like it should be easy. I’ve searched but to no avail.

    Each Page already has English content and each Page can have multiple translations, which may or may not be different per page.

    I have created a repeater field (called ‘page_translations’). This repeater field has 3 sub-fields:

    1. A select dropdown where a user can choose a language to translate to (called ‘choose_language’). The value of each <option> field is a two letter country code (e.g ‘fr’ for french)
    2. A text field to enter the Page title in the new language (called ‘translated_title’)
    3. A WYSIWYG editor field to enter the Page content in the new language (called ‘translated_content’)

    So, if an author wanted to add a French translation of a Page, they’d click the repeater button under the English content, specify French as the language then add the title and content in French. If they wanted another language too, they’d click the repeater button again and repeat the process for the new language.

    I intend to re-load each Page that has translations via a clickable URL with &tr=fr (‘fr’ is french in this example) appended to each link.

    What I was planning to do was detect if tr is set and has a value. If not, display English but if it has then pull out the translated title and content.

    I assumed ACF Repeater functions would include a ‘sibling’ call e.g. if tr equals fr get the two siblings associated with that repeater (title and content). But it seems I was wrong.

    Is there something obvious I’m missing here? If no, is there a way I can get to the siblings of the chosen language?

  • Unread

    Dynamic Accordion from Heading and Paragraph Tags

    I have one challenge that is confusing my head a little.

    If you look at this Page– https://prnt.sc/M9JDeuRYgyzY

    You will see that it has an Accordion, but we need this Accordion to show Dynamic Content pulled from Post Content.

    So that all Headings within a particular part of the Post Body will be a new Accordion Heading, and all contents below that Heading will form the Accordion Content.

    HOW IT IS SET UP
    I will create a Container, and give it a Class Name of “Post Content”.

    Inside that container, will be an ACF WYSIWYG Editor.

    WHAT IS INTENDED
    I want a code that would help me loop through the ACF WYSIWYG Editor, and pull out all the Headings(H1 to H6) and all Paragraph Text Contents within the WYSIWYG Editor.

    OUTCOME EXPECTED
    All information within this container and WYSIWYG editor needs to be displayed on the frontend as an Accordion dynamically.

    All Headings within this container and WYSIWYG editor will become each Accordion Heading, and all contents below each Heading in this WYSIWYG Editor will be the Accordion Content of each Accordion Heading.

    Example:

    In the container and WYSIWYG Editor, Heading 1 is “What is Product Management”. Then it has contents below it.

    Heading 2 in the container and WYSIWYG Editor is “Product Research”. Then it has contents below it.

    QUESTION
    How can I create a Dynamic Accordion with ACF– which will display every Heading within the specified container, as an Accordion Heading, and the Content below that Heading as the corresponding Content, in a dynamic way: such that the number of Accordion Headings and contents per Post, will be according to the Headings and contents within the specified container in the Post?

    MY THINKING
    You see, I don’t think it is possible to achieve such Dynamic Accordion in this life.

    But at the same time, such statement could be my ignorance talking :blush:

    REQUEST
    Please, if you have any smart way to achieve this with ACF, Please educate me on it.

    2.) Also show me how to make this outcome a Shortcode that I can paste anywhere on my Post or Pages.

    Needing to hear from you soon.

    Regards.

  • Solving

    Using acf_form() with Flexible Content

    Hi all,

    I’m having some issues when trying to use the flexible content with acf_form(). It appears as though the necessary scripts aren’t loading. For example the WYSIWYG editor is just showing the unstyle Add Media, Visual and Text buttons but don’t do anything when clicking on them.

    Any helps help would be greatly appreciated.

  • Unread

    One field inside of while loop show the same content for every entry

    Hello, I am writing a cpt with acf, and one of the fields, show the exact same text for every post in the CPT (the first one). If I set it as draft it moved to the second.
    The strange part is that every other field in the loop works perfectly, only this one is problematic. The field is ‘testimonial_text’;

    Here is my code:

    // Testimonial Slider Shortcode
    function testimonial_slider_shortcode($atts) {
    $atts = shortcode_atts( array(
    'category' => '',
    ), $atts, 'testimonial-slider' );
    $args = array(
    'post_type' => 'testimonials',
    'posts_per_page' => -1,
    'tax_query' => array(

    array(
    'taxonomy' => 'testimonial_category',
    'field' => 'slug',
    'terms' => $atts['category'],
    'operator' => 'AND'
    )

    )
    );

    $testimonials = new WP_Query($args);
    $output = '<div id="testimonial-slider" class="carousel slide full-width" data-ride="carousel">';
    $output .= '

      ';

      $i = 0;
      while($testimonials->have_posts()) {

      $testimonials->the_post();
      $output .= '<li data-target="#testimonial-slider" data-slide-to="'.$i.'" class="'.($i == 0 ? 'active' : '').'">';
      $i++;
      }

      wp_reset_postdata();

      $output .= '

    <div class="carousel-inner">';

    $i = 0;
    while($testimonials->have_posts()) {
    $testimonials->the_post();
    $post = get_post();
    $person_name = get_field('person_name');
    $testimonial_text = get_field('testimonial_text');
    $company_text = get_field('person_company');
    $person_photo = get_field('person_photo');
    $person_photo_url = $person_photo['sizes']['large'];

    $output .= '<div class="item '.($i == 0 ? 'active' : '').'">';
    $output .= '<div class="inner-testimonial">';

    $output .= '<div class="carousel-caption">';
    $output .= '<div class="block-quote-img">';
    $output .= '';
    $output .= 'test';
    $output .= '<span class="author-text" maxlength="2">' .$testimonial_text. '</span>';

    $output .= '</div>';
    $output .= '<p class="author">' .' - ' .$person_name.' , '.$company_text.'</p>';
    $output .= '</div>';
    $output .= '<div class="img-div">';
    $output .= ''.$person_name.'';
    $output .= '</div></div></div>';
    $i++;
    }

    wp_reset_postdata();

    $output .= '</div><span class="glyphicon glyphicon-chevron-left"></span><span class="glyphicon glyphicon-chevron-right"></span></div>';

    return $output;
    }
    add_shortcode('testimonial-slider', 'testimonial_slider_shortcode');

    // Enqueue styles and scripts
    // Global plugin styles should be added to testimonails slider.css
    // Per project styles should be added to testimonial-project.css
    function testimonial_slider_scripts() {
    wp_enqueue_style( 'testimonial-slider-style', plugins_url( '/testimonial-slider.css', __FILE__ ) );
    wp_enqueue_style( 'testimonial-project-style', plugins_url( '/testimonial-project.css', __FILE__ ) );
    // wp_enqueue_style('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css');
    // wp_enqueue_script(
    // 'testimonial-block-script',
    // plugins_url( 'blocks/testimonial-block.js', __FILE__ ),
    // array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components' )
    // );

    }

    add_action( 'wp_enqueue_scripts', 'testimonial_slider_scripts' );

    // Register Gutenberg Block

    add_action('init', 'wp_testimonial_block_init');

    function wp_testimonial_block_init() {

    register_block_type(__DIR__ . '/build', array(
    'render_callback' => 'theHTML'
    ));

    }

    function theHTML($atts) {
    $args = array(
    'post_type' => 'testimonials',
    'posts_per_page' => -1,
    'tax_query' => array(

    array(
    'taxonomy' => 'testimonial_category',
    'field' => 'slug',
    'terms' => $atts,
    'operator' => 'IN'
    )

    )
    );

    $testimonials = new WP_Query($args);
    $output = '<div id="testimonial-slider" class="carousel slide full-width" data-ride="carousel">';
    $output .= '

      ';

      $i = 0;
      while($testimonials->have_posts()) {

      $testimonials->the_post();
      $output .= '<li data-target="#testimonial-slider" data-slide-to="'.$i.'" class="'.($i == 0 ? 'active' : '').'">';
      $i++;
      }

      wp_reset_postdata();

      $output .= '

    <div class="carousel-inner">';

    $i = 0;
    while($testimonials->have_posts()) {
    $testimonials->the_post();
    $post = get_post();
    $person_name = get_field('person_name');
    $testimonial_text = get_field('testimonial_text');
    $company_text = get_field('person_company');
    $person_photo = get_field('person_photo');
    $person_photo_url = $person_photo['sizes']['large'];
    $output .= '<div class="item '.($i == 0 ? 'active' : '').'">';
    $output .= '<div class="inner-testimonial">';

    $output .= '<div class="carousel-caption">';
    $output .= '<div class="block-quote-img">';
    $output .= '';
    $output .= '<span class="author-text" maxlength="20">' .$testimonial_text. '</span>';

    $output .= '</div>';
    $output .= '<p class="author">' .' - ' .$person_name.' , '.$company_text.'</p>';
    $output .= '</div>';
    $output .= '<div class="img-div">';
    $output .= ''.$person_name.'';
    $output .= '</div></div></div>';

    $i++;
    }

    wp_reset_postdata();

    $output .= '</div><span class="glyphicon glyphicon-chevron-left"></span><span class="glyphicon glyphicon-chevron-right"></span></div>';

    return $output;
    }

    This is the code for the acf register

    // Add Custom Fields
    function add_testimonial_custom_fields() {
    if(function_exists('acf_add_local_field_group')):

    acf_add_local_field_group(array(
    'key' => 'group_testimonial',
    'title' => 'Testimonial Fields',
    'fields' => array(
    array(
    'key' => 'field_person_name',
    'label' => 'Person Name',
    'name' => 'person_name',
    'type' => 'text',
    'required' => true,
    'show_in_rest' => true,
    'wrapper' => array(
    'width' => '50',
    ),
    ),
    array(
    'key' => 'field_testimonial_text',
    'label' => 'Testimonial Text',
    'name' => 'testimonial_text',
    'type' => 'wysiwyg',
    'required' => true,
    'show_in_rest' => true,
    'wrapper' => array(
    'width' => '50',
    ),
    ),
    array(
    'key' => 'field_person_photo',
    'label' => 'Person Photo',
    'name' => 'person_photo',
    'type' => 'image',
    'preview_size' => 'full',
    'required' => false,
    'show_in_rest' => true,
    ),
    array(
    'key' => 'field_person_company',
    'label' => 'Company',
    'name' => 'person_company',
    'type' => 'text',
    'required' => false,
    'show_in_rest' => true,
    ),
    ),
    'location' => array(
    array(
    array(
    'param' => 'post_type',
    'operator' => '==',
    'value' => 'testimonials',
    ),
    ),
    ),
    ));

    endif;
    }
    add_action('acf/init', 'add_testimonial_custom_fields');

  • Solved

    Classic Editor integration

    Since the classic editor is essential for WYSIWYG fields, and was removed from wordpress core some years ago, curious if there are any plans to include classic editor with ACF, which would then remove the need for the additional plugin? If not, are there reasons for not doing so?

  • Helping

    WYSIWYG – Security Release update – 6.2.7

    Hello its not clear to my what the new update does to the_field() when its a WYSIWYG field.
    Does it remove scripts but keeps iframes?

    The blog post explains wp_kses_post runs before the_content. But what does that exactly mean for the embeds? and for the scripts?

  • Unread

    acf_form messing up with shortcodes

    Hi everybody

    i experienced somt strange behaviour with acf_form in the frontend handling shortcodes. i’ve got a wysiwyg field, and when i enter shortcode (e.g. a contact form) and save, everything looks fine. when i open the editor again, the wysiwyg contains the rendered html instead of the the shortcode. then, after saving again, everything is broken.

    am i missing any deeper settings for the acf_form, or is it a bug?

    thanks in advance for your help
    alex

  • Solved

    Page Builder w/Flexible Content. Create row

    I needed to export all existing Posts from one site to the new site. The old posts had all content in the_content() so the import sent data there in new posts. I need to move the content out of the default WYSIWYG and more it into a content block inside my ‘One Column’ block builder. I can do this no problem when the One Column has been triggered and saved with some holder text, but I am doing that manually. How can I trigger that One Column to trigger and save so I can then run an update.

    while ( have_rows('page_builder') ) : the_row();
    if( get_row_layout() == 'one_column' ): // Single Column
    /// This works only when one_column has already been created. I am starting from scratch.
    update_field('field_60745782d2943', get_the_content());
    endif;
    endwhile;

    What needs to happen to create a row layout section? I see add_action(), add_row(), update_sub_field()…. I have now wrapped myself in knots!

  • Solved

    Request: Mini WYSIWYG / Rich Text Editor Field Type

    Hi, I would really like a field type that is somewhere between a textarea field and a full WYSIWYG field.

    It would let you control the number lines like the textarea field, but it would have a very simple set of tools at the top to let you make words bold or italic, add links, or turn text into lists, without the client needing to add HTML themselves.

    Good examples of this are the Rich Text module within HubSpot and even the very text editor I am using to type this forum post.

    It would also be nice if you could customise what WYSIWYG elements are available to a user, so you could add things like font colour or size but remove the option to add list items or links.

    This would be useful for things like headings where a client user might need to make a specific word bold, but you don’t want them to rely on adding HTML to a text field, and the full WYSIWYG field just takes up too much space on the backend for something that is usually only a handful of words.

  • Solving

    ACF Field Data Disappears

    We have a problem that randomly happens. The client is so upset he wants to move away from WordPress completely. I have a simple Fieled Group with 5 text fields and one WYSIWYG Editor field, set to show if Post Type = Post. Four posts are created every evening and scheduled to be posted early the next morning. Seemingly randomly one of the posts will have missing content from the ACF fields but the rest of the post is fine. The client is adamant that he saves multiple times while creating the posts and previews all the posts as well. But if I go in to look at a post that publishes with missing ACF data, and look at post revisions the data in the custom fields will be missing from the revisions as well. I’m not seeing anything in the error logs. I have tried everything I can think of and can’t figure out why this happens. I haven’t been able to replicate it either. It’s happened twice in the past 5 days, previously it had been six weeks since this occurred.

    I’m at a loss. Any ideas on how to troubleshoot this?

  • Solved

    Should I use conditional logic to display fields?

    A very basic question that I can’t seem to find an answer to and really hope someone can advise. Sorry, it’s so simple – I can (just about) adapt php code but am not a coder.

    When I want to display the value of a WYSIWYG field, should I use the simple

    <?php the_field(‘field_name’); ?>

    Or should I put it in conditional logic in case the field value is null:

    <?php if( get_post_meta($post->ID, “field-name”, true) ): ?>
    <?php echo get_post_meta($post->ID, “field-name”, $single = true);?>
    <?php endif; ?>

    I don’t want to do anything else with these particular fields, just display them.

    I’m asking both with regards to page load speed (eg number of database queries) and also to try to prevent some of the 504 crashes my site has been having recently when I am editing pages. (The crashes began when my husband rebuilt our AWS server in order to upgrade php for the upcoming Woocommerce php change requirement; we found that changing from php 7.4 to 8.1 helped matters but has not fixed issues and so I am now looking at trying to revise/check all of my coding.)

  • Solved

    Showing custom post type field on front-end with conditional logic

    Hey!

    I have created a custom single.php template. I have a Hello Elementor Child theme. In ACF I have a Field Group. I am showing some of these Field Group fields in single.php. Now I have a true/false field, which determines if the Register Form I have created with CF7 shows if that field is checked. (Right now the Register Form is shown through the WYSIWYG field via shortcode.)

    The problem is, that the condition works only in the backend. If I uncheck the condition, the field disappears in the backend, but still shows in the front-end.

    Any ideas on how to solve this? Does it have something to do with Hello-Elementor theme?

  • Solved

    How to count the number of repeater fields within a flexible layout?

    I’m trying to get a count for the number of columns in my multi-column_row so I can use the number of columns when building my layout. I feel like i’ve tried every example I could find but I still can’t seem to get the number of rows BEFORE doing my while loop.

    Here’s my ACF Loop:

    <?php if ( have_rows( 'content' ) ): ?>
    <?php while ( have_rows( 'content' ) ) : the_row(); ?>
    <?php if ( get_row_layout() == 'text_on_white' ) : ?>
    <?php the_sub_field( 'anchor_link' ); ?>
    <?php the_sub_field( 'text' ); ?>
    <?php elseif ( get_row_layout() == 'centered_video' ) : ?>
    <?php the_sub_field( 'anchor_link' ); ?>
    <?php $thumbnail_image = get_sub_field( 'thumbnail_image' ); ?>
    <?php if ( $thumbnail_image ) : ?>
    " alt="<?php echo esc_attr( $thumbnail_image['alt'] ); ?>" />
    <?php endif; ?>
    <?php the_sub_field( 'video_url' ); ?>
    <?php elseif ( get_row_layout() == 'multi-column_row' ) : ?>
    <?php the_sub_field( 'anchor_link' ); ?>
    <?php if ( have_rows( 'columns' ) ) : ?>
    <?php while ( have_rows( 'columns' ) ) : the_row(); ?>
    <?php $image = get_sub_field( 'image' ); ?>
    <?php if ( $image ) : ?>
    " alt="<?php echo esc_attr( $image['alt'] ); ?>" />
    <?php endif; ?>
    <?php the_sub_field( 'wysiwyg' ); ?>
    <?php endwhile; ?>
    <?php else : ?>
    <?php // No rows found ?>
    <?php endif; ?>
    <?php elseif ( get_row_layout() == 'divider_line' ) : ?>
    <?php // Warning: Layout 'divider_line' has no sub fields ?>
    <?php endif; ?>
    <?php endwhile; ?>
    <?php else: ?>
    <?php // No layouts found ?>
    <?php endif; ?>

    I’ve tried
    $count = count(get_field('grid_block'));
    <?php
    $cards = get_sub_field('card');
    if(have_rows('card')):
    $number_of_cards = count($cards);
    endif; ?>

    and neither are working. Any tips?

  • Solved

    Can’t get dynamic repeater to display

    Hi there,

    I’m trying to build a more flexible template that allows the user to simply add content blocks that can be moved around using “Add Row” and then selecting from a dropdown of template blocks. I was using the advanced layout template as a guide and duplicated a number of content/template files. Exported the PHP and added to bottom of the function.php file, as well.

    The problem is that when I try to use the new template, the “Add row” button doesn’t show up, so I can’t even tell if it’s partially working. I tried adding the new segments to the Advanced Layout Template but they don’t show up in the drop down either.

    All of the new template files I’ve added were pulled from already existing template files, so I know they can work, but need something that’s not so rigid, as we currently can’t change anything or change the order without effecting every site on our website, and if we do add something, it simply doesn’t show up.

    A number of the new field groups have custom names, not sure if that matters, tried just applying a new, different template to the page we want to change, but if I do that the page becomes blank on the front end, even though the back end shows content.

    Here’s our template PHP page.

    
    <?php
    /**
     * Template Name: Master Page Builder
     */
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
      <?php //get_template_part('templates/page', 'header'); ?>
      <?php get_template_part('templates/content', 'master-page-builder'); ?>
    <?php endwhile; ?>
    

    The content file associated with the template file is below.

    
    <?php
    // SETTINGS *** Lines 3-11, possibly unnecessary **
    global $post;
    $pid = $post->ID;
    $pSlug = $post->slug;
    $parentID = $post->post_parent;
    
    // print $pid;
    // print '<br>';
    // print $parentID;
    
    //$title = get_field('title');
    $colour = get_field('theme_colour');
    $hide_content = get_field('hide_content');
    ?>
    
    <div class="trufflesTheme_<?php if ($colour) : print $colour; else : print 'indigo'; endif; ?> trufflesChildPage">
    
        <?php 
    if ($hide_content) : 
      // Return Nothing
    else : ?>
    
        <section id="trufflesMainContent" class="sectionRow truffles_content">
            <div class="inner">
                <div class="margin">
                    <?php the_content(); ?>
                </div>
            </div>
        </section>
        <?php endif; ?>
    
        <?php if (have_rows('master_content_type')) : ?>
        <section id="truffles_contentWrapper" class="truffles_contentType truffles_content">
            <?php while (have_rows('master_content_type')) : the_row(); 
      // Available Variables under sub field 'select'
      //full : Full Banner
      //small : Smaller Banner
      //imageanddesc : Image & Description
      //altimageanddesc : Image & Description (Alternative)
      //wysiwyg : Content Editor (WYSIWYG)
      //accordions : Accordions
      //logocloud : Logo Cloud
      //photocolumns : Photo Columns
      //topbanner : Header Banner
      //introduction : Introduction & Booking
      //cta : Call To Action
      //testimonials: Testimonials
      //testimonials: Video Banner
      //linkblocks: Link Blocks
      //homepageimgdesc: Image & Description Home Page Styling
      //bannerheader: Text Header
    
      $select = get_sub_field('select'); ?>
            <section class="contentType_<?php print $select; ?> sectionRow">
                <?php if ($select == 'full') : ?>
                <?php get_template_part('templates/advanced', 'full'); ?>
    
                <?php elseif ($select == 'small') : ?>
                <?php get_template_part('templates/advanced', 'small'); ?>
                <?php elseif ($select == 'imageanddesc') : ?>
                <?php get_template_part('templates/advanced', 'imageanddesc'); ?>
                <?php elseif ($select == 'altimageanddesc') : ?>
                <?php get_template_part('templates/advanced', 'altimageanddesc'); ?>
                <?php elseif ($select == 'wysiwyg') : ?>
                <?php get_template_part('templates/advanced', 'wysiwyg'); ?>
                <?php elseif ($select == 'accordions') : ?>
                <?php get_template_part('templates/advanced', 'accordions'); ?>
                <?php elseif ($select == 'logocloud') : ?>
                <?php get_template_part('templates/advanced', 'logocloud'); ?>
                <?php elseif ($select == 'photocolumns') : ?>
                <?php get_template_part('templates/advanced', 'photocolumns'); ?>
                <?php elseif ($select == 'three') : ?>
                <?php get_template_part('templates/advanced', 'threecolumns'); ?>
                <?php elseif ($select == 'embed') : ?>
                <?php get_template_part('templates/advanced', 'embed'); ?>
    
                <!--  New Content Fields -->
    
                <?php elseif ($select == 'topbanner') : ?>
                <?php get_template_part('templates/advanced', 'topbanner'); ?>
                <?php elseif ($select == 'introduction') : ?>
                <?php get_template_part('templates/advanced', 'introduction'); ?>
                <?php elseif ($select == 'cta') : ?>
                <?php get_template_part('templates/advanced', 'cta'); ?>
                <?php elseif ($select == 'testimonials') : ?>
                <?php get_template_part('templates/advanced', 'testimonials'); ?>
                <?php elseif ($select == 'videobanner') : ?>
                <?php get_template_part('templates/advanced', 'videobanner'); ?>
                <?php elseif ($select == 'linkblocks') : ?>
                <?php get_template_part('templates/advanced', 'linkblocks'); ?>
                <?php elseif ($select == 'homepageimgdesc') : ?>
                <?php get_template_part('templates/advanced', 'homepageimgdesc'); ?>
                <?php elseif ($select == 'bannerheader') : ?>
                <?php get_template_part('templates/advanced', 'bannerheader'); ?>
    
                <!-- END New Content Fields -->
    
                <?php endif; ?>
            </section>
            <?php endwhile; ?>
        </section> <!--  END #truffles_contentWrapper -->
        <?php endif; ?>
    
        <?php get_template_part('templates/footer-landing'); ?>
    </div><!-- end .trufflesTheme -->
    

    And this is referencing a number of built out fields built in php, modelled after the structure of the advanced layout template.

    Example below:

    
    <?php 
    // TESTIMONIALS
    $testimonials_section = get_sub_field('testimonials_section');
    ?>
    
    <div class="innerTable">
    
      <?php if($testimonials_section['section_content'] || $testimonials_section['testimonials_slider']):?>
        <div class="testimonials-section">
          <div class="container-wrap">
            <?php if($testimonials_section['section_content']):?>
              <div class="section-content">
                <?php echo $testimonials_section['section_content'];?>
              </div>
            <?php endif;?>
            
            <?php if($testimonials_section['testimonials_slider']):
                echo testimonial_slider($testimonials_section['testimonials_slider']);
            endif;?>
    
          </div>
        </div>
      <?php endif;?>
    </div>
    

    Which is very similar to the advanced layout template fields, like this one below.


    <?php
    // VARIABLES
    $image = get_sub_field(‘image’);
    $desc = get_sub_field(‘description’);
    ?>

    <div class=”innerTable”>
    <?php if ($image) : ?>
    <div class=”tableLeft”>
    <div class=”imageBlock”>
    <div class=”image”>
    ” alt=”Truffles Catering – <?php $image[‘alt’]; ?>” />
    </div>
    </div>
    </div>
    <?php endif; ?>
    <?php if ($desc) : ?>
    <div class=”tableRight”>
    <div class=”descBlock”>
    <div class=”desc”>
    <?php print $desc; ?>
    </div>
    </div>
    </div>
    <?php endif; ?>
    </div>

    And lastly, here’s the PHP that I exported and added to the functions.php file.

    
    /**
     * 
     * Adding New Template and Registering it
     * 
     * */
    
    add_action( 'acf/include_fields', function() {
    	if ( ! function_exists( 'acf_add_local_field_group' ) ) {
    		return;
    	}
    
    	acf_add_local_field_group( array(
    		'key' => 'group_649377b3715ff',
    		'title' => 'Master Page Builder',
    		'fields' => array(
    			array(
    				'key' => 'field_649377b3bddda',
    				'label' => 'Master Content Type',
    				'name' => 'master_content_type',
    				'aria-label' => '',
    				'type' => 'repeater',
    				'instructions' => '',
    				'required' => 0,
    				'conditional_logic' => 0,
    				'wrapper' => array(
    					'width' => '',
    					'class' => '',
    					'id' => '',
    				),
    				'collapsed' => '',
    				'min' => 0,
    				'max' => 0,
    				'layout' => 'block',
    				'button_label' => 'Add Content Row',
    				'sub_fields' => array(
    				),
    			),
    			array(
    				'key' => 'field_6493785744c19',
    				'label' => 'Navigation Menu',
    				'name' => 'navigation_menu',
    				'aria-label' => '',
    				'type' => 'select',
    				'instructions' => '',
    				'required' => 0,
    				'conditional_logic' => 0,
    				'wrapper' => array(
    					'width' => '',
    					'class' => '',
    					'id' => '',
    				),
    				'choices' => array(
    					'main-navigation' => 'Main Navigation',
    					'secondary-menu' => 'Secondary Menu',
    					'footer-menu' => 'Footer Menu',
    					'weddings-menu' => 'Weddings Menu',
    					'corporate-functions-menu' => 'Corporate Functions Menu',
    					'social-events-menu' => 'Social Events Menu',
    					'truffles-express-menu' => 'Truffles Express Menu',
    				),
    				'default_value' => false,
    				'return_format' => 'value',
    				'multiple' => 0,
    				'allow_null' => 0,
    				'ui' => 0,
    				'ajax' => 0,
    				'placeholder' => '',
    			),
    		),
    		'location' => array(
    			array(
    				array(
    					'param' => 'page_template',
    					'operator' => '==',
    					'value' => 'template-master-page-builder.php',
    				),
    			),
    		),
    		'menu_order' => 0,
    		'position' => 'normal',
    		'style' => 'default',
    		'label_placement' => 'top',
    		'instruction_placement' => 'label',
    		'hide_on_screen' => '',
    		'active' => true,
    		'description' => '',
    		'show_in_rest' => 0,
    	) );
    } );
    

    Surely, it can’t be this difficult to use ACF? Can anyone help me get this to be visible so I can add content blocks on our back-end that anyone can add, move, and (most importantly) be seen on the front-end.

    Thank you

  • Unread

    Migrate from Classic Editor to ACF Block

    Hi All,

    Has anyone found or know of a way to programmatically migrate post content from the old default WYSIWYG editor to a custom ACF block?

    Any pointers, thoughts or ideas would be much appreciated!

    Thanks

  • Unread

    Estimated Reading time for ACF Blocks

    Hi. Im trying to create a function I can use in my theme to count the words in acf blocks of type text, textarea, and wysiwyg and return an estimated reading time. No matter what I try I just cant get it, and was hoping that someone that knows acf blocks a little better than me might have an idea what is going on.

    My function:

    function estimated_reading_time($post_id) {
    	// Get the post content
    	$content = get_post_field('post_content', $post_id);
    
    	// If the post content is empty, return 0
    	if (empty($content)) {
    		return 0;
    	}
    
    	// Get the ACF Gutenberg blocks for the post
    	$blocks = parse_blocks($content);
    
    	// Debug: Output the blocks for debugging
    	var_dump($blocks);
    
    	// Initialize the word count
    	$word_count = 0;
    
    	// Loop through the blocks
    	foreach ($blocks as $block) {
    		// Debug: Output the current block for debugging
    		var_dump($block);
    
    		// Check if the block is a valid ACF Gutenberg block
    		if (isset($block['blockName']) && strpos($block['blockName'], 'acf/') === 0 && isset($block['attrs']['data']['block']['value'])) {
    			$block_fields = $block['attrs']['data']['block']['value'];
    
    			// Loop through the fields within the block
    			foreach ($block_fields as $field) {
    				if (isset($field['field_type']) && isset($field['value'])) {
    					$field_type = $field['field_type'];
    
    					// Check if the field is a text, textarea, or wysiwyg field
    					if (in_array($field_type, ['text', 'textarea', 'wysiwyg'])) {
    						$field_value = $field['value'];
    
    						// Count the number of words in the field value
    						$field_word_count = str_word_count(strip_tags($field_value));
    
    						// Add the field's word count to the total word count
    						$word_count += $field_word_count;
    					}
    				}
    			}
    		}
    	}
    
    	// Debug: Output the final word count for debugging
    	var_dump($word_count);
    
    	// Calculate the estimated reading time based on average reading speed (200 words per minute)
    	$reading_time = round($word_count / 200);
    
    	return $reading_time;
    }

    Then to use it in my template file I just do
    Reading Time: <?php echo estimated_reading_time( $postid ); ?>

    (and obviously pass that postid into the function).

    I stuck var dumps into the relevant bits to get some debugging info. But im still stuck. Any ideas what I am doing wrong?

  • Solving

    Post Content Validation

    I wanted to add a char limit to the post content but this doesn’t seem to work.
    the $value is always blank. Post content is using wysiwyg_tinymce.


    add_filter('acf/validate_value/name=_post_content', 'my_acf_validate_pcontent_value', 10, 4);
    function my_acf_validate_pcontent_value($valid, $value, $field, $input_name) {
    if($_POST['acf']['offers_form'] == 'true' && trim($value)=='') {
    return __('The description cannot be empty.');
    } elseif($_POST['acf']['offers_form'] == 'true' && strlen($value)>200) {
    return __('The description cannot be more than 200 characters.');
    }
    return $valid;
    }

Viewing 25 results - 26 through 50 (of 1,299 total)