Tagged: ,

This topic contains 2 replies, has 2 voices, and was last updated by  Steve 2 years ago.

  • Author
    Posts
  • #7825

    Stephen
    Participant

    Hi, using your examples, I set up a CPT that is using the post content field in the posts table, but displayed using piklist among my other meta fields. The problem with this (I just discovered) is that unless I put it into the “support” array in the register post type command, it will NOT show in the REST response. Any idea how to include it in the REST response without displaying it (now a second time and out of order) in my CPT admin edit screen?

  • #7826

    Stephen
    Participant

    Well, I found a workaround for this:

    add_action( 'init', 'my_custom_rest_support', 25 );
      function my_custom_rest_support() {
    
    register_rest_field( 'my-cpt','long_description',
            array(
                'get_callback'    => 'get_long_desc',
                'update_callback' => '',
                'schema' => post
            )
        );        
    
    function get_long_desc( $post_id ) {
    global $post;
    $post_content = get_post(get_the_ID());
    $content = $post_content->post_content;
        return $content;
    }
    }

    So even though this is not showing twice in the admin, I can nevertheless add the field to the json REST response. Hope this helps someone else out…

  • #7841

    Steve
    Keymaster

    Thanks for the tip!

The topic ‘REST API problem with post_content field’ is closed to new replies.