. ****/ define( 'ARCWPV', '0.1.4' ); // current version of the plugin define( 'ARCWP_DEBUG', false ); // enable or disable debug (for dev instead of echo or print_r use debug() function) define( 'ARCWP_DIR', plugins_url( '/', __FILE__ ) ); add_action( 'init', 'arcwp_init' ); function arcwp_init() { if ( ! defined( 'ARCWV' ) || is_admin() ) { return; } wp_enqueue_script( 'arcwp-script', ARCWP_DIR . '/js/arcw-popover.min.js', array( 'jquery' ), ARCWPV ); wp_register_style( 'arcwp-style', ARCWP_DIR . '/css/arcw-popover.css', array(), ARCWPV ); wp_enqueue_style( 'arcwp-style' ); wp_localize_script( 'arcwp-script', 'ajaxurl', admin_url( 'admin-ajax.php' ) ); } add_action( 'wp_ajax_get_archives_list', 'arcwp_get_archives_list' ); add_action( 'wp_ajax_nopriv_get_archives_list', 'arcwp_get_archives_list' ); function arcwp_get_archives_list() { global $wpdb; $url = $_POST['link']; parse_str( parse_url( $url, PHP_URL_QUERY ), $url ); list( $year, $month, $day ) = explode( '-', $_POST['date'] ); $params = array(); if ( isset( $url['arcf'] ) ) { $params = _arcw_get_filter_params( $url['arcf'] ); } $cat = $params['cats'] ? $params['cats'] : ''; $post_type = $params['posts'] ? $params['posts'] : 'post'; $args = array( 'posts_per_page' => 0, // 'cat' => $cat, 'orderby' => 'date', 'order' => 'DESC', 'post_type' => $post_type, 'post_status' => 'publish', 'suppress_filters' => true, 'date_query' => array( array( 'year' => $year, 'month' => $month, 'day' => $day ? $day : null, ) ) ); if ( ! empty( $cat ) ) { $args['tax_query'] = array( 'relation' => 'AND', array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $cat, 'operator' => 'IN', ), ); } $posts_array = get_posts( $args ); $max = 5; $posts = array(); for ( $i = 0; $i < count( $posts_array ) && $i < $max; $i ++ ) { $post = $posts_array[ $i ]; $posts[] = array( 'permalink' => get_post_permalink( $post->ID ), 'title' => $post->post_title ); } $json = array( 'posts' => $posts, 'post_count' => count( $posts_array ), 'max' => $max, 'more' => count( $posts_array ) > $max ? __( 'More' ) : false, 'request' => array( $cat, $post_type ) ); echo json_encode( $json ); die(); }