admin管理员组

文章数量:1303327

I'm pretty new to wordpress, I'm making an API call so it returns a certain number of posts with the same category, the meta fields and thumbnails. How can I return only the content before the READ MORE? I read that I can use the get_extended function but I can't figure out for the life of me where to put it. Here's the code at the moment:

   register_rest_route('mypage', 'recipes/(?P<quantity>[0-9]+)', array(
     'methods' => WP_REST_Server::READABLE,
     'callback' => function($request) {
       $post_type = 'recipe';
       $pages = get_posts([
         'post_type' => $post_type,
         'numberposts' => $request['quantity']
       ]);
 
      
       if ( empty( $pages ) ) {
         return [];
       }
       $recipe = [];
       $meta_fields = apply_filters('hook', null)[$post_type]['fields'];
      
       foreach ($pages as $page) {
         $page = (array)$page;
         $page['fields'] = get_post_meta($page['ID']);
         $page['thumbnail'] = get_the_post_thumbnail_url($page['ID']);
         $recipes[] = $page;
       }
    
       return $recipes;
     },
     'permission_callback' => '__return_true'
   ));

本文标签: phpShow content before more block