WordPress Ajax Request with Axios (Timber templating)

Previously when making a server-side Ajax request you would send a post request with something like this: //data contains your action and whatever other variables you are sending over $.post(ajaxurl, data,function(res){ var json_obj = JSON.parse(res); if(json_obj.message === “nomore”) { //out of posts, maybe fade out the load more button } else { // append the content … Continued

WordPress, Password Protected Data in Endpoints

I recently worked on a small Web Application using Vue on the front-end and WordPress as the backend.  The client had a static site, wanted a blog, as well as CPT for loading specific type projects (not viewable on the blog, but the static site).  Some of these projects were also password protected, and when loading … Continued

Start Extending the WordPress API

A quick run down about extending the API (see notes inside, there aren’t many right now, I need to add more, that’s my bad). This covers several scenarios and items that you may encounter yourself. Next Post Previous Post Getting the Featured Image Title Link ID Get the posts first image Get Next/Previous posts first … Continued

WordPress REST API, Get Random Post endpoint

In the following snippet, you can register a new endpoint in the API to access random posts. This can be configuring to work with any post-type.  You’ll just updating the get_posts array accordingly.  Enjoy! You’ll want to put this inside your functions.php inside your Theme, or create a plugin.  If you’re extending the WordPress REST API … Continued

How to get the Featured Image URL in WP-API V2

Formerly as seen below you could use a function to adjust the end point so it would contain a new field for the ‘featured-image‘ url.  The Rest-API v2 has now been updated so you can add ‘?_embed‘ to the parameters in your query and you’ll get exactly what you need. or You can use the following … Continued

Add Custom Post Types to WP-API V2

You’ll notice if Version 2 of the WP-API (which is phenomenal by the way), you’ll need to add a couple things here or there to grab custom data.  Grab the function and below and throw that into your functions.php inside your theme. function hijack_posts_types() { global $wp_post_types; // Add CPT slugs here, comma separated $arr = … Continued

Add Featured Image as a Background Image

Below is how you would use the featured image as a background image (also with an if statement so you can have a fallback image). <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘single-post-thumbnail’ ); $image = $image[0]; ?> <?php else : $image = get_bloginfo( ‘stylesheet_directory’) . ‘/images/default_cat_img.jpg’; ?> … Continued