Custom Fields
Support General Type post field + clone + 2k posts

  • Creator
  • #7273
    Resolved Jackky

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #7277
    Anh Tran

    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?


    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();

    and then

    					 '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(
    									'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

    Anh Tran

    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 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.