Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACF blocks are available on pages but not posts #132

Open
wearebattalion opened this issue Feb 16, 2021 · 2 comments
Open

ACF blocks are available on pages but not posts #132

wearebattalion opened this issue Feb 16, 2021 · 2 comments

Comments

@wearebattalion
Copy link

I've created a number of ACF groups (example below) as gutenberg blocks which I need to use across pages and posts, however the blocks are only available in pages and not posts, and they don't even appear when I search for them.

I've included an example of an ACF group I've created as a block below:

<?php

namespace App;
use StoutLogic\AcfBuilder\FieldsBuilder;

$newsletter = new FieldsBuilder('newsletter');

$newsletter
    ->addText('heading')
    ->addWysiwyg('content')
    ->setLocation('block', '==', 'acf/newsletter');

acf_add_local_field_group($newsletter->build());

functions.php

add_action('init', function () {
  if (function_exists('acf_add_local_field_group')) {
      // Gutenberg blocks
      collect(glob(config('theme.dir') . '/app/fields/blocks/*.php'))->map(function ($field) {
          return require_once($field);
      })->map(function ($field) {
          if ($field instanceof FieldsBuilder) {
              acf_add_local_field_group($field->build());
          }
      });
  }
});

Just to confirm, I need this block to be available on posts as well as pages.

@stevep
Copy link
Member

stevep commented Feb 16, 2021

I haven't used blocks, nor have I tried to use ACF with blocks, so my knowledge on the requirements of getting them working is very small.

Where is the block itself getting defined, when I search ACF's docs, there is a function called acf_register_block_type, and in that you can pass the post types which it should be available to:

https://www.advancedcustomfields.com/resources/acf_register_block_type/#parameters

@cheestudio
Copy link

cheestudio commented Sep 2, 2021

Just going to leave this here, but we have a lightweight "framework" that works seamlessly with ACF Builder and ACF Blocks, in case anybody wants to use it OR pick it apart for their own use! 👍🏻 It will auto register blocks that are located within a certain folder, and has built in template toggles for determining which post types the block will be available on.

https://github.com/cheestudio/startup-blocks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants