Type post field + clone + 2k posts

Support General Type post field + clone + 2k postsResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #7273
    JackkyJackky
    Participant

    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.

    #7277
    Anh TranAnh Tran
    Keymaster

    Hi 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?

    #7278
    JackkyJackky
    Participant

    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;
    

    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'
    							),
    
    #7279
    JackkyJackky
    Participant

    also offtop: 'default_state'=> 'collapsed', not working for me( Latest version installed, ofcourse

    #10318
    Anh TranAnh Tran
    Keymaster

    Hi 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 post field. No more extra queries for clones. Please update to the latest version 4.15.0.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.