In this tutorial we’re going to build a WordPress shortcode that will allow us to only show the posts of the logged in user.
This is useful if you have a website which allows authors to post their own content and you need a page to display all the posts for that author. The reason why we’re using a shortcode for this is so that we can keep the styling consistent with the other pages.
There’s a few stages to this shortcode, first you need to create a plugin to store the shortcode, then check if the user is logged in, if the user is logged in then search for posts searched by the logged in user.
Create A WordPress Shortcode
To create a WordPress shortcode you need to use the function add_shortcode(), the first parameter is the shortcode name and the second is the function to run on calling the shortcode.
add_shortcode(‘display_own_posts’, array($this, ‘display_own_posts’)); You’ll notice that the second parameter