$search, 'post_type' => $post_type, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'title', 'posts_per_page' => 20, 'no_found_rows' => true, 'cache_results' => false, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'lazy_load_term_meta' => false, ); // If number is passed if( is_numeric( $search ) ) { $args['s'] = false; $args['p'] = $search; } $search_query = get_posts( $args ); if( $search_query ) : foreach ( $search_query as $search_data ) { $post_title = ! empty( $search_data->post_title ) ? $search_data->post_title : esc_html__('Post', 'webcodexworld-events-manager'); $post_title = $post_title . " - (#{$search_data->ID})"; $return[] = array( $search_data->ID, $post_title ); } endif; } else { wp_send_json_error( array( 'message' => __( 'Sorry, Something happened wrong.', 'webcodexworld-events-manager' ) ) ); } wp_send_json( $return ); } /** * Ajax Category Suggestion. * * @since 1.0.0 */ function em_wcw_category_sugg() { // Taking some defaults $result = array(); $taxonomy = isset( $_GET['taxonomy'] ) ? em_wcw_clean( $_GET['taxonomy'] ) : EM_WCW_EVENT_CAT; $search = isset( $_GET['search'] ) ? em_wcw_clean( $_GET['search'] ) : ''; $nonce = isset( $_GET['nonce'] ) ? em_wcw_clean( $_GET['nonce'] ) : ''; if( ! empty( $taxonomy ) && $search && wp_verify_nonce( $nonce, 'em_wcw_category_sugg_nonce' ) ) { $terms_args = array( 'taxonomy' => $taxonomy, 'orderby' => 'name', 'order' => 'ASC', 'number' => 25, 'fields' => 'id=>name', 'hide_empty' => false, ); if( ctype_digit( $search ) ) { $terms_args['include'] = $search; } else { $terms_args['search'] = $search; } $terms = get_terms( $terms_args ); if( ! empty( $terms ) && ! is_wp_error( $terms ) ) { foreach ( $terms as $term_id => $term ) { $term_title = ( $term != '' ) ? $term : __('Category', 'webcodexworld-events-manager'); $term_title = $term_title . " - (#{$term_id})"; $result[] = array( $term_id, $term_title ); } } $result = apply_filters( 'em_wcw_category_sugg', $result ); } wp_send_json( $result ); } /** * Ajax callback for date format preview. * * @since 1.0.0 */ function em_wcw_date_preview() { check_ajax_referer( 'em_wcw_date_prev_nonce', 'nonce' ); $date_format = isset( $_POST['date_format'] ) ? em_wcw_clean( $_POST['date_format'] ) : ''; $preview = date_i18n( sanitize_option( 'date_format', wp_unslash( $date_format ) ) ); wp_send_json_success( array( 'preview' => $preview ) ); } /** * Add custom columns to the events list table. * * @since 1.0.0 */ function em_wcw_add_event_columns( $columns ) { $new_columns = array( 'em_wcb_start_date' => __( 'Start Date', 'webcodexworld-events-manager' ), 'em_wcb_end_date' => __( 'End Date', 'webcodexworld-events-manager' ), ); $columns = em_wcw_add_array( $columns, $new_columns, 1, true ); return $columns; } /** * Render custom columns content for the events list table. * * @since 1.0.0 */ function em_wcw_render_event_columns( $column, $post_id ) { // Getting all the general meta for the event as most of the custom columns are based on that. $prefix = EM_WCW_META_PREFIX; $start_date = get_post_meta( $post_id, $prefix.'start_date', true ); $end_date = get_post_meta( $post_id, $prefix.'end_date', true ); switch ( $column ) { case 'em_wcb_start_date': $start_date = isset( $start_date ) ? $start_date : ''; echo esc_html( $start_date ); break; case 'em_wcb_end_date': $end_date = isset( $end_date ) ? $end_date : ''; echo esc_html( $end_date ); break; } } /** * Hide some columns default. We are not removing them forcefully. * User can still enable from `Screen Options` and see the data. * * @since 1.0.0 */ function em_wcw_default_hidden_columns( $hidden, $screen, $use_defaults ) { // Event Post Type if ( $screen->id === 'edit-'.EM_WCW_EVENT_POST_TYPE ) { $hidden[] = 'author'; $hidden[] = 'comments'; } return $hidden; } }