Type post field + clone + 2k posts
- This topic has 4 replies, 2 voices, and was last updated 7 years, 5 months ago by
Anh Tran.
-
AuthorPosts
-
November 3, 2017 at 8:38 PM #7273
Jackky
ParticipantHi! 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.November 4, 2017 at 3:14 PM #7277Anh Tran
KeymasterHi Jackky,
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?
November 4, 2017 at 3:46 PM #7278Jackky
Participantyes, 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;and then
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' ),November 4, 2017 at 3:48 PM #7279Jackky
Participantalso offtop: 'default_state'=> 'collapsed', not working for me( Latest version installed, ofcourse
June 23, 2018 at 8:47 AM #10318Anh Tran
KeymasterHi Jackky,
There is a workaround on this issue, made by fexy in this topic. Please take a look.
Update: I've improved the clone feature for
postfield. No more extra queries for clones. Please update to the latest version 4.15.0. -
AuthorPosts
- You must be logged in to reply to this topic.