Help to condense/optimize some working code

Ok I figured it out. Here’s the optimized code: // Show only posts related to current user add_action(‘pre_get_posts’, ‘query_set_only_author’ ); function query_set_only_author( $wp_query ) { global $current_user; if( is_admin() && !current_user_can(‘edit_others_posts’) ) { $wp_query->set( ‘author’, $current_user->ID ); add_filter(‘views_edit-post’, ‘fix_post_counts’); } } // Fix post counts function fix_post_counts($views) { global $current_user, $wp_query; unset($views[‘mine’]); $types = array( … Read more

Getting a list of custom posts by author

Something like this should work: // Assuming you’ve got $author_id set // and your post type is called ‘your_post_type’ $args = array( ‘author’ => $author_id, ‘post_type’ => ‘your_post_type’, ); $author_posts = new WP_Query( $args ); if( $author_posts->have_posts() ) { while( $author_posts->have_posts() ) { $author_posts->the_post(); // title, content, etc $author_posts->the_title(); $author_posts->the_content(); // you should have access … Read more

Author page: Comments and Ratings?

just to add to what Rarst answered, you can create Custom Post Type not to emulate Comments but as stub posts with no ui. then to every Author on your site add a custom user metadata that will hold a post id of your newly made post type (one per each author) and in your … Read more

How to get author’s name by author’s id

Try get_user_by(): get_user_by( $field, $value ); In your case, you’d pass ID, and the user ID: // Get user object $recent_author = get_user_by( ‘ID’, $recent[“post_author”] ); // Get user display name $author_display_name = $recent_author->display_name;

Link to Author archive from Navigation Menus in dashboard?

I don’t really understand why you want to use a menu to control this but it wouldn’t be very hard. First you obviously need a new page template for your grid which you will use get_users to pull your users for display – https://codex.wordpress.org/Function_Reference/get_users Now if you want to control the order and whom is … Read more

Restrict one post per author

Answer from comments: First, create a conditional to check if the user has already ‘published’ a post. If yes, simply redirect them. One can use update_post_meta with the post ID without any problem. Simply use that information to populate the fields.

Change Comment Author Display Name

You are missing a “NOT” logical operator (!) in your if statement. You want to say “if comment author IS NOT empty”. As of now, the function is reading that the author is not empty and defaulting to your else statement that tells it to output the author’s full name. Use the second block of … Read more

Display Random Author with Details in Sidebar

Your best option is to get a random post author which is a user ID so here is a function to do just that: function get_random_author_wpa91320(){ global $wpdb; $id = $wpdb->get_var(” SELECT post_author FROM $wpdb->posts WHERE post_type=”post” AND post_status=”publish” ORDER BY RAND() LIMIT 1 “); return $id; } And once you have that function in … Read more