Jump to content

Recommended Posts

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 ?

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.

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 ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.