Woocommerce: limit user to see only the products he created

I believe changing the following conditional: if( !current_user_can( ‘manage_options’ ) ) to this one: if( !current_user_can( ‘manage_options’ ) && ‘product’ === $query->get( ‘post_type’ ) ) would do it. Brief explanation: I added a second condition which checks if the query is for WooCommerce products where the post type is product. UPDATE If you want to … Read more

WP_Query author parameter not working

First, the author parameter is parsed and appended to the author__in and author__not_in query parameters. Then author__in or author__not_in array is processed. These can be arrays created from author parameter or arrays passed as query parameteres author__in / author__not_in or created from a mergion author parameter with author__in / author__not_in parameters. Parameters author__in and author__not_in … Read more

Order users by user role

@CynthiaLara I suppose that you are using a container of WP_USER_QUERY::__construct in the form or WP_USER_QUERY or get_users or something to that effect. You can use ‘meta_key’ => ‘<YOUR_DESIGNATION_META_KEY>’,’orderby’ => ‘meta_value_num, to get results sorted by your meta key’s value. If you have used a texted based value in for this meta_key, please consider using … Read more

Exclude authors IDs from WP_Query

exclude specific authors from WP_Query You can do it like so: $args = array( ‘author__not_in’ => array( 10, 3, 4 ), ); $posts_query = new WP_Query( $args ); But if you meant “from WP_User_Query“, then in WP_User_Query, you should use the exclude parameter, and that array(‘who’ => ‘authors’) shouldn’t be in meta_query: $args = array( … Read more

Can I Include author login in post class?

Yes, you can do it pretty easily using get_the_author_meta function and post_class filter: function add_author_nicename_to_post_class( $classes, $class, $post_id ) { $classes[] = get_the_author_meta( ‘user_nicename’ ); return $classes; } add_filter( ‘post_class’, ‘add_author_nicename_to_post_class’, 10, 3 );

Author comment count in author page

all you have to do is to add an param: /* user commnet count */ function get_comment_count( $user_ID ) { global $wpdb; $count = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE user_id = %d “, $user_ID ) ); return $count; } <?php echo get_comment_count( <USER_ID> ); ?> PS. I’ve added some proper escaping in your … Read more

Noindex Posts From Certain Authors In WordPress

From codex: is_author() is a conditional tag which determines whether the query is for an existing author archive page. so it does not work for your scope. Best solution, instead of using the template file header.php is to write a function in functions.php hooking the proper action wp_head: add_action(‘wp_head’,’AS_exclude_author_from_indexing’); function AS_exclude_author_from_indexing(){ $toIndex = array(111,112,113); $user_id … Read more

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