first commit
This commit is contained in:
36
test.php
Normal file
36
test.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
include_once('wp-load.php');
|
||||
|
||||
$args = array(
|
||||
'posts_per_page' => -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.'));
|
||||
}
|
||||
Reference in New Issue
Block a user