• Sam

    (@forbiddenchunk)


    I’m hoping someone can point me in the right direction please.

    I’ve created a custom post type and got it working fine, when a user selects a specific posts it loads the single.php and then allows the user to “Save” or “Bookmark” that post to their profile page which they can view (if they’ve “saved” more than one).

    I don’t want to use a plugin.

    I’m hoping WP has something built in. I’ve googled around bookmark, save, favourite etc. and only get plugins so it’s possible just need a guide to build what I want myself…

    Thanks in advance and apologies if I’ve explained it poorly.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s no built in mechanism for bookmarks. I think it is intended for users to rely upon their browser bookmarks. To store bookmarks on your site instead, it’s mainly a matter of saving the post IDs somewhere and presenting a UI to mark/unmark posts and output a list of bookmarked posts. If the user is logged in, the marks could be stored in user meta. If you want to let random visitors bookmark, you’d need to save the marks in cookie data.

    The mark/unmark button could be built into the single.php template or as a widget that can be added to a sidebar or widget area. The list bookmarks function could be a custom page template that fetches the stored IDs and then outputs post excerpts from the previously stored IDs.

    Thread Starter Sam

    (@forbiddenchunk)

    Makes sense thanks, good way of looking at it that I hadn’t considered using post ID and user meta.

    Any guides on where to start learning these areas. I have some knowledge of not enough to dive straight in.

    Thanks again!

    Moderator bcworkz

    (@bcworkz)

    Well, nothing specific for saving post IDs in user meta, but a couple good general references are the Plugin and Theme Handbooks.

    The least disruptive way to do this is via Ajax techniques, so be sure to check out that section in the Plugins Handbook. To bookmark a post, jQuery sends the current post ID and an arbitrary “action” value to /wp-admin/admin-ajax.php/. You hook a WP action whose tag is constructed from the passed “action” value. Its callback function gets the current array of saved IDs, adds the passed ID to the array, then saves it back.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘User saves/bookmarks custom post type to profile’ is closed to new replies.