WordPress does not find author pages in search

I used this extra query in search.php: $search_string = esc_attr( trim( get_query_var(‘s’) ) ); $wp_user_query = new WP_User_Query( array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘first_name’, ‘value’ => $search_string, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘last_name’, ‘value’ => $search_string, ‘compare’ => ‘LIKE’ ) ) ) ); With a custom loop: <?php … Read more

How to update author display name on blog posts based on user role

The main culprit is this line $current_user = wp_get_current_user(); As the name “get current user” suggests, it gets you the currently logged in user. That is not what you want. Being in the the_author filter, you can use the global $authordata variable, as the function calling the filter relies on it as well. function add_verification_bagdge_to_authors($display_name) … Read more

How to only show posts assigned to current user, only in certain post types

Roles and capabilities are used to control access and normally you should use them. For example, capabilities edit_other_posts and edit_published_posts are needed to edit other user’s posts. It’s the same with othe types (pages -> edit_other_pages, edit_published_pages). Since, besides limiting the right to change other user’s posts, you also want them to be invisible, you … Read more

Retrieving Author ID in wp-admin area

It can be done like this without having to rely on the $post global. if ( is_admin() ) { if( isset( $_GET[‘post’] ) && isset( $_GET[‘action’] ) && $_GET[‘action’] === ‘edit’ ) { $post_id = $_GET[‘post’]; $current_post = get_post($post_id); $author_id = $current_post->post_author; } } The query string variable post is always the post_id you are … Read more

Get Author Post on author.php with AJAX

Author.php means you are looking at an archive of the author already, so why would you need to display posts by that author? Regardless, you can get the author ID from get_queried_object, which returns the whole user object. <?php $curauth = get_queried_object(); if($curauth && isset($curauth->ID)){ //…trigger ajax to pass ID via the data object } … Read more

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