0

Is there a way for me to have a tickbox on a category archive page that when ticked shows that category's posts on a separate page?

I'm working on a system for my work where each user will be able to 'subscribe' to a category of post and then on a 'my list' page shows posts from the categories the categories they have ticked.

I've come across a couple of posts that are close to this but with no real answer.

One suggestion was to use add_meta_data/update_meta_data which I have just had a look at. I got it so that custom meta data was added, but to change it I could only overwrite. What I was thinking was that when the a tickbox is ticked, it adds the category id to a list of other category ids and unchecked removes the id. Ideally I think it would be best if it was one field/column which stores category ids, separated by commas, that could just be pulled in to a wp_query. If there is a way of doing that then I would be fine to sort out the rest of it.

So the user process would be:

  1. Go to category page
  2. Click tick box to add or remove category
  3. Go to 'my list' page to view posts from ticked categories

I hope that is clear enough, any help would be much appreciated (even just a nudge in the right direction). Thanks.

EDIT: Apologies, apparently I wasn't clear enough. This is not a mailing system.

I'll try and explain it better.

Post 01 has category A
Post 02 has category B
Post 03 has category A
Post 04 has category C

On the category archive page for category A, Post 01 and Post 03 are displayed. In the sidebar is a tickbox that when clicked 'subscribes' them to that category. (I'm using subscribe as a general way to describe the behaviour, not as a specific term)

For this example, let's say the user has clicked the tickbox for categories A and C.

On a separate page ('My List'), the posts from all the categories a user has 'subscribed' to are displayed. In this case, that would be Post 01, Post 03 and Post 04.

3
  • Hi m.arch, could you provide more details on what you've tried already (and why it didn't work)?
    – kraftner
    Commented Feb 24, 2015 at 14:30
  • You'd need to use user meta to store which categories a user had subscribed to, then you'd need to implement a newsletter of some sort, and pass posts on a per user basis. Building any kind of custom mailing software entails risks and you should use an external service for the actual mailing part. All this implies that this is an XY problem, and you're asking how to fix your solution, not the original problem. Are you trying to use categories as separate blogs?
    – Tom J Nowell
    Commented Feb 24, 2015 at 14:48
  • Hi guys, I've just updated my question to hopefully clear it up. But yes, Tom J Nowell, I guess it is trying to use categories as separate blogs.
    – m.arch
    Commented Feb 24, 2015 at 15:03

1 Answer 1

0

So this hasn't been 100% tested yet, but the basic logic is there. The IF checks for the presence of the catID and if it isn't there; update user meta with current list + category ID.

Need to do some more work on removing from the list but it's the same principal. Check string for category ID. If exists, remove from string and store as new string. Update user meta with that string.

global $current_user;
get_currentuserinfo();

$user_id = $current_user->ID;
$currentList = $current_user->subList;
$cat_id = get_query_var('cat');
$catStr = " " . $cat_id . ",";
$update;

if (strpos($currentList,$catStr) !== false) {
echo 'ALREADY IN LIST';
}else{
echo 'ADDED TO LIST';
$update = $currentList . $catStr;
update_user_meta($user_id, 'subList', $update);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.