Skip to content

Instantly share code, notes, and snippets.

@diogenesjup
Last active April 29, 2017 01:56
Show Gist options
  • Select an option

  • Save diogenesjup/6e76635d2affd949ce45503708f5b0b6 to your computer and use it in GitHub Desktop.

Select an option

Save diogenesjup/6e76635d2affd949ce45503708f5b0b6 to your computer and use it in GitHub Desktop.
LER APENAS UM
jQuery( function( $ ) {
$( '#get-another-quote-button' ).on( 'click', function ( e ) {
e.preventDefault();
$.ajax( {
url: '/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',
success: function ( data ) {
var post = data.shift(); // The data is an array of posts. Grab the first one.
$( '#quote-title' ).text( post.title );
$( '#quote-content' ).html( post.content );
// If the Source is available, use it. Otherwise hide it.
if ( typeof post.custom_meta !== 'undefined' && typeof post.custom_meta.Source !== 'undefined' ) {
$( '#quote-source' ).html( 'Source:' + post.custom_meta.Source );
} else {
$( '#quote-source' ).text( '' );
}
},
cache: false
} );
} );
} );
LER COM FOR
jQuery(document).ready(function($){
// Call the /posts endpoint via the WordPress API
$.get("http://wpuat.com/massive/wp-json/wp/v2/posts", function (posts) {
// Loop through all the posts returned and console.log() each of
// their HTML content
$.each(posts, function(index, post) {
console.log(post.content['rendered']);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment