• Resolved Chakrapani Gautam

    (@cherrygot)


    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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You’re referring to the screen options items per page setting being limited to 99? The chosen value is saved in usermeta under the key “edit_{$taxonomy_name}_per_page”. I wonder how effective it would be to change the value directly through phpMyAdmin. I know the new value shows up in the screen options dialog, but I don’t know if it’ll actually affect the query and the list table display. I don’t have enough terms to verify.

    Give it a try! I’d be curious to learn if this works or not. I’m pretty sure the limit is set to 99 for performance reasons. How’s performance if you set it to 500 or something?

    Regarding the code block, I don’t think it’s meant to be a code editor, though I agree line numbers and syntax highlighting would be nice for output into the forums or even in our own WP pages. I think the code block is intended to receive pasted code copied from our favorite code editor. That said, I frequently compose code directly in the code block because I’m creating example code in response to a forum question. So I kind of do use it casually as a code editor ??

    If you’re interested in contributing to the Gutenberg Project, it’s managed as GitHub project. Please refer to the Contribute to Gutenberg section over at GitHub. Thank you for your interest.

    Thread Starter Chakrapani Gautam

    (@cherrygot)

    Oops, sorry. I didn’t specify where exactly in the UI I’m referring to. Hope this helps: https://ibb.co/grSNY43

    Yes, the screen options per page limit is something I’ve played around with in the past, it wasn’t that much of a problem. The issue is with this new gutenberg taxonomy sidebar. This loads the terms in the batches of 100.

    Thread Starter Chakrapani Gautam

    (@cherrygot)

    Update: I found this solution here on github issues: https://github.com/WordPress/gutenberg/issues/10169#issuecomment-488052952 and it has been working quite well for me. Although it was suggested back in 2019 and the issue is still open, I’m not sure if there are any downsides, but for now, everything looks good to me with this one.

    Turns out, I just had to use a different filter, instead of the one I mentioned earlier.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to extend the hard limit of 100 terms per request in custom taxonomy panel?’ is closed to new replies.