Skip to content

Instantly share code, notes, and snippets.

@AaronRutley
Forked from scottopolis/wp-api-jquery-ajax.html
Created October 6, 2015 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronRutley/c1d4d607c90d89d5ebfd to your computer and use it in GitHub Desktop.
Save AaronRutley/c1d4d607c90d89d5ebfd to your computer and use it in GitHub Desktop.
Simple WP-API Ajax to get posts
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>My App</title>
<style type="text/css">
body {
font-family: Arial, sans-serif;
padding: 10px;
}
ul {
list-style-type: none;
}
li {
border-bottom: 1px solid #eee;
}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>
<body>
<ul id="app"></div>
</body>
<script>
jQuery(document).ready(function($) {
$.get( "http://scottbolinger.com/wp-json/wp/v2/posts", function( data ) {
$.each( data, function( i, val ) {
$( "#app" ).append(
'<li>' +
'<h3>' +
val.title.rendered +
'</h3>' +
'<p>' +
val.excerpt.rendered +
'</p>' +
'</li>'
);
});
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment