Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Created July 9, 2018 21:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rafaehlers/1761bdaa4b36928c0e034e666f5c65de to your computer and use it in GitHub Desktop.
Save rafaehlers/1761bdaa4b36928c0e034e666f5c65de to your computer and use it in GitHub Desktop.
Code snippet for this: https://docs.gravityview.co/article/468-rest-api (Authentication section)
<?php
$entries_url = 'http://gv2.dev.codeseekah.com/wp-json/gravityview/v1/views/1696/entries.json';
$nonce = wp_create_nonce( 'wp_rest' );
?>
<script type="text/javascript">
jQuery.ajax( {
url: <?php echo json_encode( $entries_url ); ?>,
method: 'GET',
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', <?php echo json_encode( $nonce ); ?> );
},
} ).done( function ( response ) {
console.log( response );
} );
</script>
<?php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment