Get user categories with most posts in it

Your question is slightly ambiguous, but I read it this way: given an author and you want to know the three categories in which has published most posts. Let’s use wp_query to get there. $author=”johndoe”; $author_posts = new WP_Query (array ( ‘author’ => $author, ‘posts_per_page’=>-1, )); Now we have an array of all posts by … Read more

How to add user details to different tables immediately after user registration

Removing the table names from the column names when using $wpdb->insert() is what worked for me: function add_to_affuser($user_id) { global $wpdb; $user_info = get_userdata($user_id ); $wpdb->insert( ‘mytbl_A’, array(‘name’ => $user_info->user_login, ’email’ => $user_info->user_email ), array(‘%s’, ‘%s’) ); } add_action( ‘user_register’, ‘add_to_affuser’); function add_to_aff($user_id) { global $wpdb; $user_info = get_userdata($user_id); $wpdb->insert( ‘mytbl_B’, array(‘user_id’ => $user_info->ID ), … Read more

I am getting mysql_real_escape_string() function error while adding user?

The problem is from wp_insert_user and the fact that your value for user_pass is empty. You should update your code as so $random_password = wp_generate_password(8,false); $user_data = array( ‘user_login’ => $first_name, ‘user_pass’ => $random_password, ‘user_email’ => $trainer_email, ‘first_name’ => $first_name, ‘last_name’ => $last_name, ‘role’ => ‘trainer’ ); And remove this line wp_set_password($random_password, $user_id); You should … Read more

mySQL statment count of post in each category and sub category

You may try this amateur code. SELECT COUNT(ID) FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (1) ) AND wp_posts.post_type=”post” AND ((wp_posts.post_status=”publish”)) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC Note the term_taxonomy_id IN (1) is where your category ID is 1. You may remove the line for published … Read more