Hello Developers,
If you want to display the content of your blog post in your app. Then you need to create a php page with names display_blog.php (you can change this name) in your previous API folder and paste below code :
<?php
require ("../wp-load.php");
$args = array(
'post_type' => "post",
'author' => $_GET['user_id'],
'post_status' => 'publish',
'posts_per_page' => -1,
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) : $the_query->the_post();
$b[] = array(
"id" => get_the_ID(),
"name" => get_the_title(),
);
endwhile;
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
echo json_encode ($b);
?>
You can also pass user id in url so you can fetch blog post according to user or you can remove this line :
'author' => $_GET['user_id'],
Then you need to call this url :
www.webtecso.com/api/display_blog.php?usser_id={Your user id}
If you want to display the content of your blog post in your app. Then you need to create a php page with names display_blog.php (you can change this name) in your previous API folder and paste below code :
<?php
require ("../wp-load.php");
$args = array(
'post_type' => "post",
'author' => $_GET['user_id'],
'post_status' => 'publish',
'posts_per_page' => -1,
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) : $the_query->the_post();
$b[] = array(
"id" => get_the_ID(),
"name" => get_the_title(),
);
endwhile;
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
echo json_encode ($b);
?>
You can also pass user id in url so you can fetch blog post according to user or you can remove this line :
'author' => $_GET['user_id'],
Then you need to call this url :
www.webtecso.com/api/display_blog.php?usser_id={Your user id}
Comments
Post a Comment