Can i check if user is doing any ajax request?

You’d be better off moving your function that updates the meta to a hook that runs on the front end and during AJAX calls. Then you don’t need to bother about checking if the request is an AJAX request or not. init is a good choice for this: function wpse_297026_update_user_activity() { update_user_meta( get_current_user_id(), ‘last_activity’, time() … Read more

include user profiles in search results?

I haven’t an ready to use solution. However I think you should enhance the query, so that you have the field of the users inside this. I think the follow example demonstrate it more. The two filter hooks are necessary and get an result for the query like this: SELECT SQL_CALC_FOUND_ROWS wpbeta_posts.ID FROM wpbeta_posts JOIN … Read more

How to Save Different Usermeta Fields According to User Role?

Observation: following the guidelines suggested in this article, I’m trying to improve the quality both of the Q and the A. It’s a learning process… In your original code, you were displaying different input fields according to the user role and other conditionals. add_action( ‘show_user_profile’, ‘user_fields_for_admin’, 10); add_action( ‘edit_user_profile’, ‘user_fields_for_admin’, 10); function user_fields_for_admin( $user ){ … Read more

How to count current user’s pages?

Look what count_user_posts() does inside and change the post type parameter: global $wpdb; // ‘page’ is the important part here $where = get_posts_by_author_sql(‘page’, true, $userid); $count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->posts $where” ); Then you change your snippet to: global $wpdb; $user = wp_get_current_user(); $where = get_posts_by_author_sql( ‘page’, true, $user->ID ); $count = $wpdb->get_var( … Read more

How to stop a user from updating the post date

As @t-f pointed out in his comment to question, you have an error on checking current user capability: ‘delete_published_posts’. $post_author_id simply doesn’t exist. After that, for your scope probably is a better hookin the filter wp_insert_post_data instead of the action save_post: because this one run when the post was already saved / updated, so if … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)