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

Add Sequential Classes to loop, WordPress

Below are to examples you will probably need the most.  Adding a sequential class to a for loop, and adding a sequential class to a while loop For Loop <?php global $post; $cntr = 1; $myposts = get_posts(‘category=1&numberposts=3&order=des’); foreach($myposts as $post) : setup_postdata($post);?> <li class=”<?php echo “post-” . $cntr; ?>”><a href=”<?php the_permalink() ?>”><?php the_title() ?></a></li> … Continued

WP REST API (WP API), Tips and Tricks

I’m starting to use the WP API more and more, and have definitely needed some help along the way.  Here are some tips and tricks I’ve been able to pick up and use. Get multiple types of posts / pages / etc /wp-json/posts?type[]=post-type&type[]=post-type Filter by specific number of posts per page /wp-json/posts?filter[posts_per_page]=4&page=2 (number of posts … Continued

Display posts from WordPress custom post type

There are more than a few way to show a Custom Post Type in WordPress.  This has been by far the best way to not just show custom post types, normal posts, but also retain a lot of WordPress default functionality. <?php $args = array( ‘post_type’ => ‘any-post-type’, ‘posts_per_page’ => 4, ); $query = query_posts($args); … Continued