function nottice_similar_sorts($interface) { if ($interface->sortID == '' || $interface->current_sort_view_ID == '') { return; } //check if autsort Yes, oterwise we don't care about similar sorts. if ($interface->sort_settings['_autosort'] != 'yes') { return; } $apto_system_nottices = array(); //get all sorts $args = array('post_type' => 'apto_sort', 'post_parent' => 0, 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => -1, 'post__not_in' => array($interface->sortID), 'ignore_custom_sort' => TRUE); $custom_query = new WP_Query($args); if ($custom_query->have_posts()) { global $post; $_wp_query_post = $post; while ($custom_query->have_posts()) { $custom_query->the_post(); $found_similar = TRUE; $sort_settings = APTO_functions::get_sort_settings($post->ID); //check if autosort is turned on if ($sort_settings['_autosort'] != 'yes') { continue; } //check if same post types rules if (count($interface->sort_settings['_rules']['post_type']) != count($sort_settings['_rules']['post_type']) || count(array_diff($interface->sort_settings['_rules']['post_type'], $sort_settings['_rules']['post_type'])) > 0) { continue; } //check if same taxonomy settings if ($interface->sort_settings['_rules']['taxonomy_relation'] != $sort_settings['_rules']['taxonomy_relation'] || count($interface->sort_settings['_rules']['taxonomy']) != count($sort_settings['_rules']['taxonomy']) || $this->taxonomy_settings_diff_exist($interface->sort_settings['_rules']['taxonomy'], $sort_settings['_rules']['taxonomy']) === TRUE) { continue; } //check if same author rules if (count($interface->sort_settings['_rules']['author']) != count($sort_settings['_rules']['author']) || count(array_diff($interface->sort_settings['_rules']['author'], $sort_settings['_rules']['author'])) > 0) { continue; } //check for same conditionals if (count($interface->sort_settings['_conditionals']) != count($sort_settings['_conditionals']) || $this->conditional_settings_diff_exist($interface->sort_settings['_conditionals'], $sort_settings['_conditionals']) === TRUE) { continue; } if ($found_similar === TRUE) { $link_argv = array('sort_id' => $post->ID); $link_argv['page'] = 'apto_' . sanitize_title($sort_settings['_location']); $link_argv['base_url'] = admin_url($sort_settings['_location']); $url = APTO_interface_helper::get_item_link($link_argv); $message = __("Notice: There is", 'apto') . ' <b><a href="' . $url . '">' . __("another", 'apto') . '</a></b> ' . __("similar sort", 'apto'); if ($post->ID < $interface->sortID) { $message .= ' which will be used instead.'; } else { $message .= ', however current list will be used.'; } $apto_system_nottices[] = $message; } } //wp_reset_postdata(); //use this instead as using a setup_postdata() without any query will reset to nothing $post = $_wp_query_post; } if (count($apto_system_nottices) > 0) { echo "<div id='notice' class='updated fade'><p>" . implode("</p><p>", $apto_system_nottices) . "</p></div>"; } }
static function create_post_type_sort($post_type, $options, $sort_view_meta) { $post_type_data = get_post_type_object($post_type); //create the sort $post_data = array('post_type' => 'apto_sort', 'post_status' => 'publish', 'post_title' => 'Sort #' . $post_type_data->label); $sort_id = wp_insert_post($post_data); $rules = array(); $rules['post_type'] = array($post_type); update_post_meta($sort_id, '_rules', $rules); //process the conditionals $conditionals = array(); update_post_meta($sort_id, '_conditionals', $conditionals); foreach ($options as $option_key => $value) { //add as meta value update_post_meta($sort_id, $option_key, $value); } update_post_meta($sort_id, '_view_type', 'multiple'); //create the default view for this sortID $sort_view_id = APTO_interface_helper::create_view($sort_id, $sort_view_meta); //set this sort view as default for the main sort update_post_meta($sort_id, '_last_sort_view_ID', $sort_view_id); return $sort_id; }