Display posts with author in the url with custom post types

You can use the %author% tag in the rewrite property in register_post_type(). However, although the rewrite rules are added (after they’re flushed) – WordPress doesn’t replace the tag with its appropriate value when generating the permalink of your post type. For instance you end up with the permalink www.example.com/%author%/gallery-name The following replaces %author% with the … Read more

Check If comment author is registered

I wonder if you mean this kind of check: if( $comment->user_id > 0 ) { // Registered comment author } in your comment’s template callback. This is determined in the the wp-comments-post.php file: $commentdata = compact(‘comment_post_ID’, …, ‘user_ID’ ); $comment_id = wp_new_comment( $commentdata ); but it’s not obvious where the user_ID variable comes from, since … Read more

Display Authors Comments on Profile Page

What you need to use here is the WP_Comment_Query() function. So on the author.php page, you can easily get the author info and ID as followed: // get author info $curauth = (isset($_GET[‘author_name’])) ? get_user_by(‘slug’, $author_name) : get_userdata(intval($author)); // set ID $user_id = $curauth->ID; Then we add the user ID in the query arguments array: … Read more

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;

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