create a template page for a post

You can add a rewrite tag and rules that capture anything after the post name: function wpd_add_rewrites(){ add_rewrite_tag( ‘%my_page%’, ‘(.+)’ ); $post_types = array( ‘movie’, ‘book’, ‘album’ ); foreach( $post_types as $post_type ){ add_rewrite_rule( ‘^’ . $post_type . ‘/([^/]*)/([^/]*)/?’, ‘index.php?post_type=” . $post_type . “&name=$matches[1]&my_page=$matches[2]’, ‘top’ ); } } add_action( ‘init’, ‘wpd_add_rewrites’ ); Don’t forget, you … Read more

Update permalinks when new category added to custom post type taxonomy

That’s not how custom taxonomies and post types work This is what you do: On the init hook, call register_custom_taxonomy or register_post_type If you change your calls to register_custom_taxonomy or register_post_type, or add new ones in your code, regenerate permalinks by visiting the permalinks settings page and clicking save You’re done So if I follow … Read more

Regenerate Thumbnails

add_image_size is intended to be defined globally (outside of the context of a post type). This is because when images are generated they are not yet attached to a specific post type. If you’re using a plugin or WP CLI to regenerate the thumbnails, you are outside of the context of a post type. Therefore … Read more

How inefficient is it to use a Custom Post for 4-5 sentences & pull all to 1 page?

Considering the requirements that you’ve outlined, custom post types are definitely an appropriate choice for managing resources within WordPress. You get a CRUD interface right out of the box (just in case you’d like to leverage it) and WP All Import works nicely with WordPress posts, meta data, and taxonomies. There are great APIs for … Read more

How can I update the permalink everywhere for a custom post type?

This line: $post_link = str_replace( “https://wordpress.stackexchange.com/” . $post->post_type . “https://wordpress.stackexchange.com/”, “https://wordpress.stackexchange.com/”, $post_link ); isn’t doing what you expect because your post slug isn’t $post->post_type, it’s sp, as set here: $rewrite = array( ‘slug’ => ‘sp’, ‘with_front’ => false, ‘pages’ => true, ‘feeds’ => true, );

Update post terms with custom taxonomy

Yes it is. But you have to know the exact taxonomy’s slug, since colors are not like preserved terms to be generated programmatically. Here is an example of how to do it: // run our function when a post is published add_action(‘save_post’,’update_my_taxonomies’); function update_my_taxonomies($post_id){ // Check if the post has a particular taxonomy if(has_term( ‘blue’, … Read more

Loading custom post thumbnail into stream

You can write a function to grab the featured image by post’s ID, then manipulate it and return it as whatever format you wish. function covert_thumbnail_to_base64($post->ID){ // Get the thumbnail’s URL $thumbnail = get_the_post_thumbnail_url( $post->ID,’thumbnail’ ); // Now, process it the way you want // Return the processed image return $data; } Now you can … Read more