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 Options page fields #199

Open
3 tasks done
BogdanKozhevnik opened this issue Apr 21, 2024 · 1 comment
Open
3 tasks done

ACF Options page fields #199

BogdanKozhevnik opened this issue Apr 21, 2024 · 1 comment
Labels
needs: reproduction This issue needs to be reproduced independently

Comments

@BogdanKozhevnik
Copy link

BogdanKozhevnik commented Apr 21, 2024

Description

  1. in the old plugin I can only register the options page manually, WPGraphQL for Advanced Custom Fields does not add the page to the graphql schema. However manually it works and I can create acf fields and add them to the page. I completely disable Polylang synchronization for acf and only use the language switcher for the options page. Fields store different values according to language, and so does the result by language during GraphQL queries. It works fine with the old plugin. However, there is another problem, I created a Gutenberg block with acf fields, but in the GraphQL response I get an incorrect data schema even if I use my own render template.
function acf_blocks() {
    if( function_exists('acf_register_block') ) {
        acf_register_block(array(
            'name'              => 'banner',
            'title'             => __('Banner'),
            'description'       => __('A custom banner block.'),
            'category'          => 'formatting',
            'render_template'   => 'template-parts/blocks/banner.php',
            'icon'              => 'dashicons-embed-photo',
            'keywords'          => array( 'banner', 'photos' ),
        ));
    }
}

/**
 * Block Name: Banner
 */
$title = get_field('title') ?: 'Title;
$text = get_field('text') ?: 'Text';
$image = get_field('image') ?: 'Image';
?>
<style>
    .banner {
        border: 1px solid #e0e0e0;
        border-radius: 5px;
        margin-bottom: 20px;
    }
</style>
<div class="banner">
    <h2><?php echo $title; ?></h2>
    <p><?php echo $text; ?></p>
    <?php if( $image ): ?>
        <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
    <?php endif; ?>
</div>

Then i put it to the post and try to get blocks.

query GetPosts {
  posts(where: {language: EN}) {
    nodes {
      blocksJSON
    }
  }
}

image
As you can see, the image contains only the id, although the acf image field contains both the title and the link.

  1. But with the new plugin the situation is even more complicated. Now it adds the options pages to the grapgl schema, but it is not possible to get the fields according to the language. The schema doesn't even show the language argument with LanguageCodeEnum. It only appears if this page is added via code:
acf_add_options_page(array(
    'page_title' => 'Blog Settings',
    'menu_title' => 'Blog Settings',
    'menu_slug' => 'blog',
    'capability' => 'edit_posts',
    'redirect' => false,
    'show_in_graphql' => true,
    'graphql_field_name' => 'blog',
));

,but still doesn't work. And although the fields on the options page store different values ​​for different languages, you can't get them by language. It always return either the default value or null.

List of my plugins:
image

fields on options page
image

query
image

acf Fields
image

Steps to reproduce

Just try to get ACF Options Page fields by locale
Just try to get fields from acf gutenberg block by locale

PHP or JSON export of the ACF Field Group(s)

acf-export-2024-04-21.json

Additional context

No response

WPGraphQL Version

1.23.0

WPGraphQL For ACF Version

old 0.6.1 beta 2, new 2.2.0

ACF (Advanced Custom Fields) Version. Free or Pro?

6.2.9 pro

WordPress Version

6.5.2

PHP Version

8.1

Additional enviornment details

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have disabled ALL plugins except for WPGraphQL, WPGraphQL For ACF, ACF, etc.

  • Yes
  • My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.
@josephfusco josephfusco added the needs: reproduction This issue needs to be reproduced independently label Apr 22, 2024
@BogdanKozhevnik
Copy link
Author

hi, do you need some additional information to reproduce bug? I can write it step-by-step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: reproduction This issue needs to be reproduced independently
Projects
None yet
Development

No branches or pull requests

2 participants