Grandioso Posted August 17, 2012 Share Posted August 17, 2012 I want my users to be able to mark posts as favorite. I tried the wp-favorite-posts plugin, but it doesn't work. I mark posts as favorites and after refreshing the page it's all gone. Furthermore, if I put {{wp-favorite-posts}} to a page, it just shows the text. So I want to create my own solution, but don't really know how. I have never edited the WP database, but I have plenty of PHP mySQL experience. Can anyone please point me in the right direction ? What I would do is make a table called 'fav_posts' to connect user ID's with post ID, so it would have 2 rows. I suppose I could figure out adding posts. There would be a link with the current user ID and post ID somewhere in it. The link would trigger an ajax event which would create the new DB record or delete it if 'unfavorite' was clicked. Now the harder part would be getting the posts, somehow combining the new table with the WP query. I could create an empty page, and in page.php and add a condition to check if the current page is the favs page. But how do I output only the fav posts ? Quote Link to comment https://forums.phpfreaks.com/topic/267223-wordpress-how-to-create-a-fav-posts-feature/ Share on other sites More sharing options...
Mahngiel Posted August 17, 2012 Share Posted August 17, 2012 I mark posts as favorites and after refreshing the page it's all gone. Sounds like you're not saving anything. So I want to create my own solution, but don't really know how. I have never edited the WP database, but I have plenty of PHP mySQL experience. It shouldn't take anybody long to figure out the schema behind a database if you have any experience with mysql What I would do is make a table called 'fav_posts' to connect user ID's with post ID, so it would have 2 rows. I suppose I could figure out adding posts. There would be a link with the current user ID and post ID somewhere in it. The link would trigger an ajax event which would create the new DB record or delete it if 'unfavorite' was clicked. Now the harder part would be getting the posts, somehow combining the new table with the WP query. I could create an empty page, and in page.php and add a condition to check if the current page is the favs page. But how do I output only the fav posts ? Sounds like you're implementing a user bookmarking system. You need to prepare your articles with some sort of identification. I'd suggest adding the post's id to the element that contains the post body. This will give your javascript something to find. Your backend script will catch that ID, ensure the user is logged in, and input an entry with the user's ID and the aforementioned post ID. Then, when the user requests his 'bookmarks', you query the table for matches on the user ID and retrieve all posts associated with post IDs. Quote Link to comment https://forums.phpfreaks.com/topic/267223-wordpress-how-to-create-a-fav-posts-feature/#findComment-1370186 Share on other sites More sharing options...
Grandioso Posted August 19, 2012 Author Share Posted August 19, 2012 OK, I could get the post IDs to display, but is there a way to display posts without having to create yet another loop ? I already have the same code in my index.php and loop.php. Loop.php is used for the infinite scrolling. Can I somehow call the loop.php file from a page and tell it to load just the user's favorite posts ? Quote Link to comment https://forums.phpfreaks.com/topic/267223-wordpress-how-to-create-a-fav-posts-feature/#findComment-1370641 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.