/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* require the user as the parameter */ /* soak in the passed variable or set our own */ /* connect to the db */ /* grab the posts from the db */ $query = "SELECT post_title, guid FROM wp_posts WHERE post_author = $user_id AND post_status = 'publish' ORDER BY ID DESC LIMIT $number_of_posts"; /* create one master array of the records */ } } /* output in necessary format */ if($format == 'json') { } else { echo '<posts>'; foreach($posts as $index => $post) { foreach($post as $key => $value) { echo '<',$key,'>'; foreach($value as $tag => $val) { } } echo '</',$key,'>'; } } } echo '</posts>'; } /* disconnect from the db */ }
URL: http://davidwalsh.name/web-service-php-mysql-xml-json