The latest update for my Media Search Enhanced (MSE) plugin will be supporting MIME type and date filters in the Media Library. It’s funny that I never use these filters myself, so in the past two years there was such a major bug in the plugin and I never noticed.
Save Dev Machine Space By Displaying Images From Production Server
Be sure to check out the original post. If you’re on Nginx, just use the following gist for the images URL rewriting. View the code on Gist.
Parent Post From Another Post Type And A New URL Structure In WordPress
Hello, beautiful readers! In this post we are going to solve a very specific need for custom post types in WordPress. I’ve actually written about it two years ago, which is to select post parent from another post type. But today you’ll learn more deeply on the same topic with a live example.
Say there’s a project for building online courses website, we plan to have two custom post types in WordPress, which are “Courses” and “Lessons”. Registering two CPTs won’t be a big deal for us but the not-so-easy part is we’d like to set the URL structure of the lessons in such format:
Taking my AngularJS series for example, it would look like:
So the workflow to manage our online course would be like, we always add a new course first, input some course information, prerequisites, curriculum etc. After that we’ll create as many lessons as needed, and for each lesson, we have to set the “parent post” for it, which is the course it’s attached to.
If you find this use case compelling, keep reading and here’s what I’m going to show you (preview the final demo if you’d like):
- Registering two custom post types: Courses and Lessons.
- Updating the “Parent” meta box so we can choose a “course” as the parent post for a “lesson”.
- Setting the exactly URL structure we want.
- Updating the permalink of the CPT to reflect the new URL structure.
Ready? Let’s go!
Getting Categories With Posts In A Single WP API Request
UPDATED March 03, 2016: Post has been updated. Now we use "rest_prepare_category" filter for this job. UPDATED March 02, 2016: With the latest WP API V2 Beta12, the filter "
rest_prepare_term" I used in this post no longer work and it should be changed to "
rest_prepare_category". I'll update the post content ASAP.
A while back ago I wrote a post to show you how to “Adding Fields To The JSON Response Of The WP REST API“. In the first scenario why we’ll ever need to add fields to WP API, is for people who want to build an accordion menu with categories as the first level links, which when being clicked, the posts would be collapsed as the second level links.
We know we could use WP API to get a single category info, and we can also get the posts for a certain category, but unfortunately we can’t do both in a single API request.
Display Post Excerpt To The More Tag With WP API V2
Ho Ho Ho! It’s December now so you get a Santa-style greeting from me! Today I’ll be showing you a simple trick that I got asked a while back ago in one of the comments, that is: “how can we display excerpt to the more tag (<!–more–>) with WP API V2”?
By default, WP API V2 has the
excerpt field in the posts response, but the auto generated one is often not what we want.
So here are things we’d like to hack around the WP API and get the results we want:
- Get the excerpt with read more link
- Get the excerpt from text before the more tag
- Display content of the shortcodes or oEmbed links in your excerpt
Now let’s get started.
Cookie Authentication In A AngularJS WordPress Theme
Hello beautiful readers! Glad to see you again so soon. Today I’d like to share my findings about cookie authentication and our AngularJS WordPress theme. I’ll show you how exactly to get the cookie authentication working with the theme, and we’ll create a simple AngularJS custom directive to display the user name if she/he is logged in.
What I’ll be showing you in this post I actually spent over two months to figure that out (duh!). Eventually to my surprise that cookie authentication is quite simple when we are just building WordPress themes or plugins.