0

Hello WordPress community,

I'm working on a project where I need to create a custom post type using Advanced Custom Fields (ACF) and query it via WPGraphQL to integrate with a Headless Next.js build. Specifically, I want to achieve the following:

  • Single Instance Custom Post Type: I want to create a custom post type called "Homepage" that allows only one instance to exist. This single instance will represent the homepage of the website.

  • Limited Module Options: Within this "Homepage" custom post type, I'd like to restrict the editor to adding only a predefined set of modules (e.g., hero section, featured posts, gallery, etc.). The goal is to provide a structured and controlled editing experience.

  • Integration with WPGraphQL: Once the "Homepage" custom post type is set up with its limited module options, I intend to query this
    data using WPGraphQL to retrieve and render it within a Headless
    Next.js frontend.

I've already registered the custom post type using ACF, but I'm unsure how to enforce the single instance constraint and restrict the module options for the editor. Additionally, I'd appreciate any guidance on how to effectively query this custom post type data via WPGraphQL for seamless integration with Next.js.

Any advice, code examples, or resources related to achieving these goals would be greatly appreciated!

Thank you in advance for your assistance.

Best regards,

J

    1 Answer 1

    1

    Custom Post types just don't really work like you want them to. "Post" types are fundamentally repeating types. My recommendation would be to use the pre-existing "Page" post type to create a home page. Here's some high-level steps

    1. Create a "Home" page under Pages
    2. In your site's "Reading" Settings select that page as your "Homepage"Screenshot
    3. Create an ACF Field Group that only applies to that page.

    If this doesn't work for you, try creating a cause "Options Page" with ACF (Requires Pro). That is a non-repeating type with only a single instance.

    1
    • This can all also be done without ACF, you just have to code up your own custom fields and metaboxes or use WP built-in Custom Fields.CommentedOct 14, 2024 at 1:51

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.