Ajax call fails
-
When opening a webinar for editing, the AJAX action ‘wpws_get_pages_and_posts’ fails because it tries to return ALL the published posts and pages. This is not only a poor thought and bad performance, but also it’s very bad and fails on websites with a lot of posts. Can this be addressed ASAP on the PRO version?
Snippet of Uri, AJAX action and callback function:
//URI
/wp-admin/admin.php?page=wswbn-webinars&webinar_id=588390
// AJAX call
add_action(‘wp_ajax_wpws_get_pages_and_posts’, [‘WebinarSysteemAjax’, ‘get_pages_and_posts’]);
// Callback function from\wp-content\plugins\wpwebinarsystem\includes\class-webinarsysteem-ajax.phppublic static function get_pages_and_posts() { WebinarSysteemJS::check_ajax_nonce(); function title_filter($where) { global $wpdb; // this is messy, there must be a way to pass $query into the filter? $query = empty($_POST['query']) && $_POST['query'] != '' ? null : strtolower($_POST['query']); if ($query != null) { $where .= ' AND '.$wpdb->posts.'.post_title LIKE \'%' . esc_sql(like_escape($query)).'%\''; } return $where; } add_filter('posts_where', 'title_filter', 10, 2); $posts = get_posts([ 'post_type' => ['page', 'post'], 'posts_per_page' => -1, 'orderby' => 'post_title', 'order' => 'ASC', 'suppress_filters' => false ]); remove_filter('posts_where', 'title_filter', 10); self::return_data( array_map(function ($row) { return [ 'id' => (int)$row->ID, 'title' => $row->post_title ]; }, $posts) ); }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Ajax call fails’ is closed to new replies.