Support

Account

Forum Replies Created

  • `
    window.tinyMCE.init({ selector:#${div.id} .wp-editor-area})
    `

  • You should be able to call acf_register_block() (which has been renamed to acf_register_block_type() in 5.8.0 release) multiple times in a row without any issues.
    I think the issue might be that the $blocks variable does not contain the blocks data.

    try to do the end of the blocks file like so:

    
    // blocks.php
    ..
    
    $blocks = [
      $headline,
      $paragraph
    ];
    return $blocks;
    

    You can then get the value like so:

    
    // index.php
    function block_acf_init()
    {
        $blocks = require(__DIR__.'/blocks.php');
        
        foreach($blocks as $block) {
            acf_register_block($block);
        }
    }
    
  • If you’re worried the acf_add_local_field_group() syntax is wrong, you could instead create the field group inside the WordPress dashboard (Custom Fields > Add New).
    and then export it as PHP (Custom Fields > Tools > Select Field Group > Generate PHP).

    Don’t forget to remove the field group again once you’ve put it in PHP.

  • If you’re trying to get fields bound to the page itself (and not another block), you could get it by passing the page id to the get_field function:

    
    $value = get_field('my_field', $post_id);
    
  • From what I understand you’re working inside an ACF block and want to get data from another block on the same page.

    You can get block data from a page like so:

    
    $post = get_post($post_id);
    $blocks = parse_blocks($post->post_content);
    

    $blocks here will be an array of all blocks in the page, this includes their basic info and all the data (fields).

  • I debugged acf-input.json for a bit.

    Inside ACF’s initializeQuicktags() default settings are retrieved like so:
    `
    var defaults = {
    tinymce: tinyMCEPreInit.mceInit.acf_content,
    quicktags: tinyMCEPreInit.qtInit.acf_content
    };
    `
    I decided to console.log(tinyMCEPreInit) here and in my attachment are my results. On the left is my custom page, on the right a default ACF options page.

    As you can see, my custom page is missing the acf_content field under mceInit.

  • YES, finally made some progress!
    I fixed the repeater’s add row button by running the following JS function after loading the fields:
    window.acf.doAction('load')

    Now I only need to fix the visual field 🙂

  • Thanks for your input so far. 🙂
    I think my best option is to check out the javascript files. Hopefully I can find an init function.

  • ACF is probably used to initialising on page load. However my fields are loaded using AJAX, and need to be initialised whenever loaded.

    Maybe there’s a JavaScript function I could call to initialise all fields on the page? :S

  • Thanks for the answer @hube2 . I decided to compare my page to a regular acf options page created using acf_add_options_page().

    ACF is not loading all of the needed scripts
    By default ACF doesn’t load the scripts, no, but I make use of acf_enqueue_scripts() which loads the same two acf javascript files a regular options page loads (acf-input & acf-pro-input).

    The markup on your page needs to be exactly the same
    My page, just like an options page, is loaded as a WordPress admin page. The rendering of the form itself is handled by ACF, the exact page doesn’t look the same but I doubt this would be an issue.

  • For example these are a few fields that are being received.
    The radios work just fine, but the add row button does nothing.
    screenshot fields

    Here is a text field, and the error in the console that’s shown when Visual is clicked.
    screenshot text field

  • To be able to use full and wide align, you must run a theme that supports it, this requires the theme to set an option and add some CSS.
    Twentynineteen supports this, but if you’re running your own theme you can add support for it yourself. How to do this is written in this article.

    Now about the bit of code you sent, setting 'align' => 'full' should be correct and set the default alignment to full. Maybe try recreating your block to see if it’s set to full then?

  • Situation & Problem
    I’m implementing a custom admin page that gets ACF fields based on a selection.
    Everything is working fine, including the showing and saving of the fields.

    However, after a field is loaded using Ajax, certain JavaScript functionalities are not working:

    • In a repeater field, the add row button does nothing, it also shows nothing in the console when clicked.
      According to my browser a click event IS bound to it from acf-input.js:
      return a.apply(b || this, c.concat(e.call(arguments)))
    • In a wysiwyg field, the Visual button does not work. When clicked it shows the following error in the console: TypeError: r is undefined [tinymce.min.js]

    Am I maybe supposed to perform a JavaScript call to initialise the newly loaded fields? Or is there something wrong with my implementation of ACF?

    Info on my implementation
    Initial page load
    On initial page load I run acf_enqueue_scripts(); to load all ACF scripts/styling.

    Getting fields with Ajax
    On the page when a selection is made, an Ajax call is made to a custom route which performs the following to get the fields HTML:

    
    // get fields based on group key received from POST request
    $fields = acf_get_fields(['key' => $key]);
    
    // render fields, and use output buffering to catch the HTML
    ob_start();
    acf_render_fields($fields, 'my-page');
    $fields_html = ob_get_contents();
    ob_end_clean();
    
    return $fields_html;
    

    Which successfully returns the required HTML to the page.

    Saving Fields
    I very simply perform a POST with all the fields to a route which performs the acf_save_post('my-page') function.
    This function gets the fields from the request and saves them, which works wonderfully.

Viewing 13 posts - 1 through 13 (of 13 total)