rewind_posts(); return $query[$entry_type_key]; } $query[$entry_type_key] = new \WP_Query( [ 'post_type' => self::POST_TYPE, 'orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => -1, 'meta_query' => [ [ 'key' => 'entry_type', 'value' => ':"' . $entry_type_key . '";', // пошук в серіалізованому масиві 'compare' => 'LIKE' ] ], ] ); return $query[$entry_type_key]; } public static function register_post_type() { register_post_type( self::POST_TYPE, [ 'labels' => [ 'name' => 'Products', 'singular_name' => 'Product', 'add_new' => 'Add New Product', 'add_new_item' => 'New Product', 'edit_item' => 'Edit Product', 'new_item' => 'New Product', 'view_item' => 'View Product', 'search_items' => 'Search Product', 'not_found' => 'Product was not found', 'not_found_in_trash' => 'No Product was found in Trash', 'parent_item_colon' => '', 'menu_name' => 'Products', ], 'description' => '', 'public' => true, 'show_ui' => true, 'show_in_menu' => false, 'capability_type' => 'post', 'hierarchical' => false, 'supports' => ['title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'page-attributes'], 'taxonomies' => [], 'has_archive' => false, 'rewrite' => [ 'slug' => 'product', ], 'query_var' => true, ] ); } public static function enqueue_scripts( array $script_options ) { wp_enqueue_script( 'fasoon_quote_step6_products', plugins_url( '/js/fasoon-quote-step6-products.js', FQP_PLUGIN_BASE_NAME ), [ 'jquery', 'fasoon_quote_step6' ] ); wp_localize_script( 'fasoon_quote_step6_products', 'fasoon_quote_step6_products_vars', $script_options ); } public static function acf_entry_type_field_choices( $field ) { $ets = DB::get_entry_types(); $bts = DB::get_backing_types(); $with = fqp__( 'with' ); $field['choices'] = []; foreach ( $ets as $et ) { if ( 'y' == $et['hasBacking'] ) { foreach ( $bts as $bt ) { $key = "{$et['ID']}_{$bt['ID']}"; $title = "{$et['title']} {$with} {$bt['title']}"; $field['choices'][$key] = $title; } } else { $field['choices'][$et['ID']] = $et['title']; } } return $field; } public static function add_post_columns( $columns ) { end( $columns ); $last_key = key( $columns ); $last_value = $columns[$last_key]; unset( $columns[$last_key] ); $columns['entry_type'] = fqp__( 'Legal Form' ); $columns[$last_key] = $last_value; return $columns; } public static function post_columns_values( $column_name, $post_ID ) { switch ( $column_name ) { case 'entry_type': $entry_types = get_field( $column_name, $post_ID ); echo self::post_columns_entry_type_value( $entry_types ); break; } } public static function post_columns_entry_type_value( $entry_types ) { if ( empty( $entry_types ) ) { return '-'; } $ets = DB::get_entry_types(); $bts = DB::get_backing_types(); $value = '