I have 3000 users and 2800 user without publication, so i want to delete all spam user with sql. thanks
Your question isn't very clear -
But if you mean "delete all users who have never posted anything" - Then
DELETE FROM `wp_users`
WHERE ID NOT IN
(SELECT DISTINCT post_author FROM `wp_posts`);
would do it... remember to back up your data first.
This will run through all the posts, make a list of the user IDs that ARE authors and then delete anyone who isn’t on the list from your wordpress users. Since custom post types are stored in wp_posts, it’ll be checking the author against all of those too.
Related
These are my tables:
Author
author_id text
Client
client_id text
Post
author_id text
post_id text
Follow
client_id text
author_id text
I am having trouble modeling the follow table to achieve the following:
1)Client can fetch all the posts from authors which he is currently following
2)Client can follow then unfollow then follow and so on...
3)Whenever an author adds a post, clients receive a notification for the post(this is done through another service(firebase) which doesn't provide a way to fetch previous notifications)
4)Client can fetch all previous notifications he received(i'm having trouble with this point)
Does anybody have an idea how to model my tables to be able to query for the last point.
Thank you
If you want to be able to track the history of a client following an author, rather than just the current state, then you need effective start and end dates on your Follow table.
This will also allow you to track theoretical notifications (i.e. when a notification should have gone out). If you want to track actual notifications then you would need your notification process to record successful notifications in a table.
Your Post table also need a date column
I need to get all the users who have joined (are members) of a site (blog) in WordPress multisite.
To complicate it, I am doing this outside of WordPress and don't have access to internal Wordpress functions, so need to construct the SQL directly.
In English the SQL would break down as "get an array of user IDs of users that are members of site x" (where site relates to one of the WordPress Multisite sites).
I've tried going through WordPress code to understand, but struggling with the above.
I don't need the PHP, I can work that out, just an example SQL statement.
Many thanks!
select * from wp_blogs
From the output of the command note down the blog_id you want the users of. For eg: say you are wanting the users of the site with blog_id = 2 , next run the following query.
select * from wp_users u join wp_usermeta um on u.id=um.user_id where um.meta_key="wp_2_capabilities"
Thanks for this code, just what I needed!
If it helps anyone else, I also extended it a bit to get how many people have a given role, e.g. a custom role teacher was used below:
select * from wp_users u join wp_usermeta um on u.id=um.user_id where um.meta_key="wp_2_capabilities" AND um.meta_value LIKE '%teacher%'
This of course requires other roles not to contain the word teacher (e.g. maybe there's a role ex-teacher which it would also pick up). That was the case for me so I ran two queries and subtracted the two numbers.
If anyone knows how to do it with one query that would be nice?
I found the following SQL script here in another thread:
DELETE FROM `wp_posts`
WHERE `post_type` = 'post'
AND DATEDIFF(NOW(), `post_date`) > 120
This script will find and delete all posts older than 120 days.
However, I'm wondering if this can also be done in certain categories only.
I'd like to keep all the old posts in some categories, but delete all old posts in others.
Also, if so, is there a way to make this script run every day?
I'm extremely green when it comes to this sort of thing, so any help will be greatly appreciated.
You'd better use wp_delete_post ( http://codex.wordpress.org/Function_Reference/wp_delete_post ) function to do what you wanna do, because there a lot of relationships beetween posts comments etc. in the database. => http://codex.wordpress.org/images/9/9e/WP3.0-ERD.png
To run this script everyday you have to make a CRON job on your server :
http://www.thesitewizard.com/general/set-cron-job.shtml
hope it helps
I want to manage a n-label comment system and design a data base structure like this.
I am trying to design a database which supports comment moderation for unregistered users. The functionality I require is such that when a comment is posted
If the user is registered it appears directly. otherwise;
The post must be checked by a moderator before it appears.
Please suggest the possible changes to my database schema above to support this functionality.
It appears that you have more-or-less what you require in order to do what you want. The process when a user creates a new comment is as follows
if the user is registered, and not blocked
create BlogComment record with:
IsApproved=true
IsBlocked=false
UserId=registered userId
UserName = null
if the user is registered and blocked
create BlogComment record with
IsApproved=false
IsBlocked=true
UserId=registered userId
UserName = null
if the user is unregistered
create BlogComment record with
IsApproved=false
IsBlocked=false
UserId=null
UserName=user's name
When you pull out comments to show below a post you want a query like
SELECT Comment, ISNULL(bc.UserName, ru.UserName) AS UserName
FROM BlogComment bc
LEFT JOIN RegisteredUser ru
ON bc.UserId = ru.Id
WHERE postId=<current PostId>
AND IsApproved=1
This will pull out all approved comments (those from registered users, or from unregistered users which have been moderated), along with their username (for registered users this will be their username from the RegisteredUser table, for unregistered it will be what is saved alongside their comment in the BlogComment table)
Lastly, when you want to pull out a list of posts for the moderator to moderate
SELECT *
FROM BlogComment
WHERE IsApproved=0
AND IsBlocked=0
You can then update the records they accept to IsApproved=1.
I run a forum which I built myself. Ok so all users have the opportunity to delete themselves.
But all their threads and posts will remain. But right now where it should say their username it's just blank.
How should I handle this?
Should I make a new user and call it e.g. "deleted user" and assign all threads/posts to that ID when they delete themselves?
Or should I just check if the user ID exist if not print e.g. "deleted user" as username?
What's the smartest way? Any other ways tell me.
Thanks!
p.s (i'm not a native english speaker, looked up some fancy words on a online dictionary)
I would suggest not actually deleting the user. You could simply add a column to the users table such as:
ALTER TABLE users ADD COLUMN (is_active TINYINT(1) NOT NULL DEFAULT 1);
Then when you "delete" a user, simply mark them as inactive:
UPDATE users SET is_active = 0 WHERE users.id = 7;
For user listings, and account access you would check the is_active status. For displaying of data such as posts and what not, you'd not care about their active status, youd just grab the name from the table.