Monday 21 August 2017

Get wordpress post using webservice

Get wordpress post using webservice


Get wordpress post using webservice, wordpress, wordpress websevice, get post using webservice, 



<?php

require_once '../wp-load.php';
require_once '../wp-config.php';
header('Content-type: application/json');

$response = array();
$count = 0;

$args = array(
        'post_type' => 'owl-carousel',
'posts_per_page' => -1,
        'orderby' => get_option('owl_carousel_orderby', 'post_date'),
        'order' => 'asc',
        'tax_query' => array(
            array(
                'taxonomy' => 'Carousel',
                'field' => 'slug',
                'terms' => 'home'
            )
        ),
        'nopaging' => true
    );

$my_query = null;
$my_query = new WP_Query($args);

if( $my_query->have_posts() )
{
$response['message'] = 'Banner list';
$response['status'] = 1;

while ($my_query->have_posts()) : $my_query->the_post();
   
$response['data'][$count]['id'] = get_the_ID();
$response['data'][$count]['title'] = html_entity_decode(get_the_title());
$response['data'][$count]['imageurl'] = wp_get_attachment_url( get_post_thumbnail_id($my_query->ID));
$count++;

endwhile;
}
else
{
$response['message'] = 'No banner exists.';
$response['status'] = 2;
}

echo json_encode($response);

?>

No comments:

Post a Comment

Thank You For Comment