I would like to create a shortcode that will extract information for a custom post, and display it within a Page or regular Post.
Specific use case: I have a custom post type “Film” for a film festival website. The films are displayed with their own single-film.php, but occasionally the site owners want to write a post or page that mentions a particular film, and would like to be able to pull snippets of the info that has already been entered (eg, Film name, booking info, etc). This would go in a “box” at the bottom of the post, and I’d like to make it easy for them by providing some sort of shortcode.
How would I go about doing this? Any recommended resources/tutorials to get me on the right track? What gotchas should I be aware of (eg, multiple loops in a post)?
There are great tutorials about shortcodes all over the web and some good examples here
but just to get you started:
and to use it enter in any post/page:
just change FILM_POST_ID to the actual Film post ID.
Hope this helps
Try to start from this tutorial.
In the callback function, do a custom_query (or use get_post) for the post and extract only the values that are relevant for you. (I.e: title, excerpt…)
example shorcode
Use id in your function to retrive the content of the film.