How do you retrieve a post by slug name through REST API?
Posts: sitename.com/wp-json/wp/v2/posts?slug=post-slug Pages: sitename.com/wp-json/wp/v2/pages?slug=page-slug Custom post type: sitename.com/wp-json/wp/v2/POST_TYPE?slug=post-slug
Posts: sitename.com/wp-json/wp/v2/posts?slug=post-slug Pages: sitename.com/wp-json/wp/v2/pages?slug=page-slug Custom post type: sitename.com/wp-json/wp/v2/POST_TYPE?slug=post-slug
The following code will work, but you just have to keep in mind that conflicts can happen easily if the slug for your custom post type is the same as a page or post’s slug… First, we will remove the slug from the permalink: function na_remove_slug( $post_link, $post, $leavename ) { if ( ‘events’ != … Read more
You are asking two questions at once: What’s the difference between home_url() and site_url()? How do I get WordPress to return the URL root without the subdirectory where it’s installed? Here are the answers, and I confirmed with Andrew Nacin, a core developer of WordPress, as well as ran some server tests to confirm what … Read more
get_permalink() is only really useful for single pages and posts, and only works inside the loop. The simplest way I’ve seen is this: global $wp; echo home_url( $wp->request ) $wp->request includes the path part of the URL, eg. /path/to/page and home_url() outputs the URL in Settings > General, but you can append a path to … Read more