add_filter('register_post_type_args', static function ($args, $post_type) { if ('portfolio' === $post_type) { $args['show_in_rest'] = true; $args['rest_base'] = 'portfolio'; $args['rest_namespace'] = 'wp/v2'; $args['rest_controller_class'] = 'WP_REST_Posts_Controller'; } return $args; }, 10, 2);add_action('init', static function () { foreach (array('page', 'portfolio') as $post_type) { if (!post_type_exists($post_type)) { continue; }add_post_type_support($post_type, 'custom-fields'); $registered = get_registered_meta_keys('post', $post_type);foreach (array('_yoast_wpseo_title', '_yoast_wpseo_metadesc') as $key) { if (!empty($registered[$key]['show_in_rest'])) { continue; }register_post_meta($post_type, $key, array( 'type' => 'string', 'single' => true, 'show_in_rest' => true, 'sanitize_callback' => 'sanitize_text_field', 'auth_callback' => static function ($allowed, $key, $post_id) { return current_user_can('edit_post', (int) $post_id); }, )); } } }, 30);

Controladores de Dominio: Gestión y Optimización