وردپرس

How to extend the hard limit of 100 terms per request in custom taxonomy panel?


As the title says, I am looking for a way to extend the hard limit of 100 terms per request of taxonomy panels in Gutenberg editor. I’m working on a site that has about 1000 terms in one of the taxonomies and it takes 9 such 100 terms request before the taxonomy panel renders completely. On local machine, it’s barely noticeable. But not in the production environment.

A snapshot of requests: https://ibb.co/SJVQWk5

I want to to try requesting around 1000 terms in single request to check if the situation improves in term of wait times.

So far, I’ve been able to extend the maximum limit of per_page from REST API responses using the following piece of code.

\add_filter( "rest_{$taxonomy}_collection_params", function( $query_params ) {    
  if ( isset( $query_params['per_page'] ) && isset( $query_params['per_page']['maximum'] ) ) {         
    $query_params['per_page']['maximum'] = 1000;    
  }    

  return $query_params;  
} );

(Btw, if anyone who maintains the code block of this forum editor, please get in touch or show me the light. I want to help and work on to improve this block. It just outright sucks pasting code here. Plus no syntax highlighting either.)

And this is has worked for me when I’m making custom REST API requests. The WP site is having no issues sending them in bulk.

However, this change in the limit is not reflected in the requests made by the taxonomy panel of the gutenberg. I still see 9 requests of 100 items each. How to override this behaviour?

So far, I’ve been able to locate that the panel makes the query with per_page parameter set to -1 . Here: https://github.com/WordPress/gutenberg/blob/wp/6.1/packages/editor/src/components/post-taxonomies/hierarchical-term-selector.js#L32

But as I follow this line of code to dig deeper, I’m lost in the react codebase and can’t pin point where the hard limit it set. My guess is that this has to do something with entityConfig here: https://github.com/WordPress/gutenberg/blob/wp/6.1/packages/core-data/src/entities.js#L311 but I’m not 100% sure.

Has anyone gone down this rabbit hole?

این خبر را در ایران وب سازان مرجع وب و فناوری دنبال کنید

مشاهده پاسخ های این مطلب
———————————————
این مطلب از سایت انجمن وردپرس گردآوری شده است و کلیه حقوق مطلق به انجمن وردپرس می باشد در صورت مغایرت و یا بروز مشکل اطلاع دهید تا حذف گردد

منبع: انجمن وردپرس

دکمه بازگشت به بالا