-1, 'post_type' => 'post', 'lang' => 'pl', ); $query = new WP_Query( $args ); $i = 0; if ( $query->have_posts() ) { $posts_data = array(); while ( $query->have_posts() ) { $i++; $query->the_post(); $post_data = array( 'id' => $i, 'title' => get_the_title(), 'url' => get_permalink(), ); $posts_data[] = $post_data; } header('Content-Type: application/json'); echo json_encode($posts_data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); wp_reset_postdata(); } else { echo json_encode(array('error' => 'not found.')); }