Support » Developing with WordPress » Getting custom fields for a post from within Gutenberg

  • I’m building a block that is basically a staff display block, it pulls data from a custom post type called “Staff” and displays it in a div. I am selecting this data via a select box in the sidebar that is populated with the custom post types. When I choose my staff member from the select box, I get all the information I need, except for the custom fields.
    This is how I’m getting my post list:

    
    edit: withSelect( function( select ) {
                return {
                    posts: select( 'core' ).getEntityRecords( 'postType', 'lawyers' )
                };
            } ) ( function( props ) {
    

    How do I get the custom fields for these posts inside a block?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Someone has to know how to do this, right? I mean, custom fields are still accessible in Gutenberg, right?

    Moderator bcworkz

    (@bcworkz)

    Please do not bump topics in these forums. Not only does it not have the effect you desire, it actually works against you because in doing so, your topic falls off the “no replies” view that most experts here in the best position to help you use to find those still needing help.

    I’m not up to speed with editor blocks, but I can tell you that the data does exist on the edit screen’s DOM, but extracting field data via HTML elements is an inherently weak solution. I would look at either passing data to client scripts via wp_localize_script() or by making an Ajax request to the API to fetch the desired data. Note that meta data needs to be explicitly registered for the API for it to be accessible.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting custom fields for a post from within Gutenberg’ is closed to new replies.