Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once "wp-load.php";
- if ( ! function_exists( 'post_exists' ) ) {
- require_once( ABSPATH . 'wp-admin/includes/post.php' );
- }
- function create_new_br_product_filter($post_title,$args=[]) {
- $defaults=array (
- 'data' =>
- array (
- ),
- 'br_wp_footer' => '',
- 'widget_type' => 'filter',
- 'reset_hide' => '',
- 'title' => '',
- 'filter_type' => 'attribute',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'type' => '',
- 'select_first_element_text' => '',
- 'operator' => 'OR',
- 'order_values_by' => '',
- 'order_values_type' => 'asc',
- 'text_before_price' => '',
- 'text_after_price' => '',
- 'enable_slider_inputs' => '',
- 'parent_product_cat' => '',
- 'depth_count' => '',
- 'widget_collapse_enable' => '',
- 'widget_is_hide' => '',
- 'show_product_count_per_attr' => '',
- 'hide_child_attributes' => '',
- 'hide_collapse_arrow' => '',
- 'use_value_with_color' => '',
- 'values_per_row' => '',
- 'icon_before_title' => '',
- 'icon_after_title' => '',
- 'icon_before_value' => '',
- 'icon_after_value' => '',
- 'price_values' => '',
- 'description' => '',
- 'css_class' => '',
- 'use_min_price' => '',
- 'min_price' => '',
- 'use_max_price' => '',
- 'max_price' => '',
- 'height' => 'auto',
- 'scroll_theme' => 'dark',
- 'selected_area_show' => '',
- 'hide_selected_arrow' => '',
- 'selected_is_hide' => '',
- 'slider_default' => '',
- 'number_style' => '',
- 'number_style_thousand_separate' => '',
- 'number_style_decimal_separate' => '.',
- 'number_style_decimal_number' => '2',
- 'is_hide_mobile' => '',
- 'user_can_see' => '',
- 'cat_propagation' => '',
- 'product_cat' => '',
- 'parent_product_cat_current' => '',
- 'attribute_count' => '',
- 'child_parent' => '',
- 'child_parent_depth' => '',
- 'child_parent_no_values' => '',
- 'child_parent_previous' => '',
- 'child_parent_no_products' => '',
- 'child_onew_count' => '',
- 'child_onew_childs' =>
- array (
- 1 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 2 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 3 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 4 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 5 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 6 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 7 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 8 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 9 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- 10 =>
- array (
- 'title' => '',
- 'no_product' => '',
- 'no_values' => '',
- 'previous' => '',
- ),
- ),
- 'search_box_link_type' => '',
- 'search_box_url' => '',
- 'search_box_category' => '',
- 'search_box_count' => '',
- 'search_box_attributes' =>
- array (
- 1 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 2 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 3 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 4 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 5 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 6 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 7 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 8 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 9 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- 10 =>
- array (
- 'type' => '',
- 'attribute' => '',
- 'custom_taxonomy' => '',
- 'title' => '',
- 'visual_type' => '',
- ),
- ),
- 'search_box_style' =>
- array (
- 'position' => '',
- 'search_position' => '',
- 'search_text' => '',
- 'background' => '',
- 'back_opacity' => '',
- 'button_background' => '',
- 'button_background_over' => '',
- 'text_color' => '',
- 'text_color_over' => '',
- ),
- 'ranges' =>
- array (
- 0 => '',
- 1 => '',
- ),
- 'hide_first_last_ranges' => '',
- 'include_exclude_select' => '',
- 'include_exclude_list' =>
- array (
- ),
- 'version' => '1.0',
- 'filter_title' => $post_title,
- 'cat_value_limit' => '',
- 'style' => 'divi_checkbox',
- 'widget_collapse' => '',
- 'attribute_count_show_hide' => '',
- 'custom_price_ranges_text' => '',
- );
- $args=array_merge($defaults,$args);
- $fount_post = post_exists( $post_title,'','','br_product_filter');
- if ($fount_post===0) {
- $post_id = wp_insert_post(array(
- 'post_title' => $post_title,
- 'post_content' => '',
- 'post_type' => 'br_product_filter',
- 'post_status' => 'publish'
- ));
- if (!is_wp_error($post_id)) {
- update_post_meta($post_id,'br_product_filter',$args);
- }
- }else {
- echo "Filter $post_title exists";
- $post_id=$fount_post;
- }
- return $post_id;
- }
- // create filter
- $br_filter_id=create_new_br_product_filter('Test filter',[
- 'filter_type' => 'attribute',
- 'attribute' => 'pa_test',
- ]);
- // assign filter to existing group
- $br_filters_group_id=385;
- $br_filters_group_meta=get_post_meta($br_filters_group_id,'br_filters_group',true);
- if (!in_array($br_filter_id,$br_filters_group_meta['filters'])) {
- array_push($br_filters_group_meta['filters'],$br_filter_id);
- }
- update_post_meta($br_filters_group_id,'br_filters_group',$br_filters_group_meta);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement