Hi! I got a real problem: I have created a clonable group with post (select_advanced) field inside. I have about 2k posts in DB, so when I have a 10x clones - I got 10x get_posts query with result of all my posts with x10 multiplier.
What I suggest: create a very simple param for post field type + select advanced, that will allow to get_posts remotely via ajax autocomplete.
Thanks for your suggestion. But that doesn't really reduces the number of requests. Do you mean *only* query when typing in the select_advanced? What about clicking on the field as select a post?
yes, autocomplete, than typing 2-3 letters. Also you first thouth right - if you will make request via ajax to standart query for all posts - it will not reduce the number of requests, but it will improve the page loading time with requesting heavy query async. Also for now, I have reduced my admin page load time from 30s to 6s (it's localhost, prod server more better) with simple construction:
$all_products = ; $args = array( 'posts_per_page' => -1, 'post_type' => 'product' ); $query = new WP_Query( $args ); if ( $query->have_posts() ): while ( $query->have_posts() ): $query->the_post(); $all_products[get_the_ID()] = get_the_title(); endwhile; endif;
array( 'id' => 'order_products', 'type' => 'group', 'clone' => true, 'sort_clone' => true, 'collapsible' => true, 'save_state' => true, 'default_state'=> 'collapsed', 'group_title' => array( 'field' => 'product_id' ), 'add_button' => 'Добавить товар', 'fields' => array( array( 'name' => 'Товар', 'id' => 'product_id', 'type' => 'select_advanced', 'options' => $all_products, 'class' => 'product_id' ),
also offtop: 'default_state'=> 'collapsed', not working for me( Latest version installed, ofcourse