I have put together a custom registration form on my WordPress site and one of the items on the registration form is an ability to select an interest.
Essentially I have the following code from the registration form…
update_usermeta( $user_id, 'interests', $_POST['interests'] );
I would need a code that does something like, if “interestes” matches “tag” of a new post, then send an email to the user.
Anything like that possible? Thank you in advance!
See this example on the question 19259.
The function was init on publish a post, change the hook to your post type or use on default
post
– Hookpublish_post
. Before you send check in the function your custom user meta field, likeget_user_meta( $user_id, 'interests', TRUE );
and ready to send the information about new post.Maybe liek this solution, but untested!
A other alternative way is to use a plugin and leave many time, like this free plugin Inform about Content.
The plugin add two fields to the user profile for update of post and comment via mail. You can enhance with a custom plugin to the register site for new users to fill up this fields.
Why reinvent the wheel? You should be able to hook into
wp_update_user
and then add the users email/remove it via a plugin like subscribe2 based on the value of that field.If you want a more custom solution you could create your own plugin and do something like:
Which is copy and pasted from the Plugin API
This would have to be modified with your if statement and a for-each but other than that should work. I would recommend just going with the first option though.