Skip to content

Instantly share code, notes, and snippets.

@kjtolsma
Created June 22, 2016 11:55
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 kjtolsma/e49b1ad3737c5f173b45cab6512a5555 to your computer and use it in GitHub Desktop.
Save kjtolsma/e49b1ad3737c5f173b45cab6512a5555 to your computer and use it in GitHub Desktop.
$( '.load-random-post' ).on( 'click', function( e ) {
$.ajax( {
url: themePostData.postsEndpointURL,
data: {
filter: {
'posts_per_page': 1,
'orderby': 'rand'
},
},
dataType: 'json',
type: 'GET',
success: function( data ) {
var postTitle = data[0]['title']['rendered'];
var section = $( '.post' );
section.find( '.entry-title' ).hide().html( postTitle ).fadeIn( 'slow' );
},
cache: false
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment