5

You can modify all main queries before they happen via the pre_get_posts action and a check if is_main_query: function wpa75492_post_type_query( $query ) { if ( $query->is_main_query() ) { $query->set( 'post_type', array( 'book' ) ); } } add_action( 'pre_get_posts', 'wpa75492_post_type_query' );


5

You will want to implement that using AJAX. Read these two articles from the Codex for further information about integrating Wordpress with some AJAX action: AJAX AJAX in Plugins Just to give you a head start, you will want something like this: Client-side (Javascript) $(element).click(function() { var data = { action: 'get_author_info', ...


5

your problem is using author_email, you need user_id: i just use similar script. <?php $args = array( 'user_id' => get_the_author_meta('ID'), 'number' => 10, // how many comments to retrieve 'status' => 'approve' ); $comments = get_comments( $args ); if ( $comments ) { $output.= "<ul&...


5

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 ...


4

You can do this using both client-side and server-side validation. If you're doing something on the client-side then you should duplicate the functionality on the server, too. Modern debugging tools make it far too easy to circumvent JavaScript functionality. This questions lends itself well to begin solved as plugin, so I'm approaching it as such. First, ...


4

I found the answer to this from @bybloggers answer found here. https://wordpress.stackexchange.com/a/58793/12920 I modified his code very slightly to tailor it to my needs, but this is the code that worked for me and was exactly what I was looking for: // Create the query var so that WP catches the custom /member/username url function ...


4

Don't run a new query in the template, modify the main query before it's run via the pre_get_posts action in the theme's functions.php file. function wpd_author_query( $query ) { if ( $query->is_author() && $query->is_main_query() ) { // your code to set $current_user_name here $query->set( 'meta_key', '...


4

As I have stated in comments, you would want to use pre_get_posts to add your custom post type to your author archive pages. In addition, once that is done, it is easy to sort the posts, you simply need to run the main loop twice, once only sending the custom post type posts to screen and the second time only post posts. Here is an example: (NOTE: This is ...


3

Basic debugging... $current_author = get_query_var('author'); var_dump($current_author); ... would reveal that $current_author is a string, not an object. The problem is that you are trying to use the string as an object in the query. get_posts( 'author='.$current_author->id.'&posts_per_page=1&order=DESC&orderby=post_date' ); Change $...


3

You have a couple of issues here, the main one being that your query sets posts per page to two, but the number of pages available has no relationship to your custom query. If your "Blog pages show at most" under Reading settings is set to 10, and an author only has <= 10 posts, there is no second page. The other issue you will discover is that you're ...


3

toscho is correct. User levels have been deprecated for a long time now. However, the following will get you the available information about the author of the posts on an author archive page. $author = get_queried_object(); var_dump($author); In that dump you should see everything you need, but use the role not the user level-- look in $author->roles. ...


3

This is a very simple PHP issue, unrelated to WordPress. You need to check if the value is empty before echoing it. So, store them as variables first: $twitter = get_the_author_meta('twitter', $author_id); $facebook = get_the_author_meta('facebook', $author_id); //etc Then check them before displaying: if(!empty($twitter)) { echo '<a title="Follow ...


3

If you are talking about author.php in your theme directory, usually at wp-content/themes/<YOURTHEMENAME> this isn't a core file but part of your theme. Themes don't get changed when WordPress is updated, so concerning WordPress updates themes are safe. But if your theme isn't custom made by you (which I assume here) this file would be changed if you ...


3

An easy way is to use a static variable to store author name, then run again same function on a later hook, maybe 'posts_results' and set back the variable: function wpquery( $query, $query_on_results = NULL ) { static $author_name = NULL; if ( current_filter() === 'pre_get_posts' ) { if ( $query->is_author() && $query->is_main_query() ...


3

When the loop is complete, have_posts() rewinds it back by calling the rewind_posts() method of the $wp_query object, see here. Here's another (more simple?) setup that you could try: while( have_posts()): the_post(); if ( 0 == $wp_query->current_post ): // post 1 elseif ( 1 == $wp_query->current_post ): // post 2 ...


3

Do not use query_posts, and for that matter any custom query to replace the main query. It is always problematic and it creates more problems that solving it. Use the main query and make use of pre_get_posts to alter the main query as needed. To solve your issue, remove the query_posts line, this is how author.php should look. <?php if(isset($_GET[...


3

The template_include hook allows you to change which template file is going to be used. In it, you can conditionally check if it's an author page requested, then use get_query_var() to get the requested author. You then check the authors role and see if it's what you don't want, and use a different template if so. Below is untested, but something like: ...


2

<?php if(!empty($curauth->description)) { ?> <div class="title">About me</div> <div class="descwrap"> <div class="descinner"> <?php echo $curauth->description; ?> </div> </div> <?php } ?> This should work for you. It checks if the variable is empty or not (http://...


2

Could be because you are passing an array of array try this: <?php $my_query = new WP_Query(); $my_query->query(array( 'post__in' => $curauth->user_favourite_post)); while ($my_query->have_posts()) : $my_query->the_post(); ?> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> ...


2

I cracked it! In my case I first created an author.php page (my theme lacked one) from the archive.php by cloning and cleaning it. Then I found this piece of code: <?php if ( have_posts() ) : ?> It basically says: if the authors has published some posts, then... Well, I just added: "OR NOT!" <?php if ( have_posts() || !have_posts() ) : ?> ...


2

The mistake is in your first block of code: <?php if (have_posts()): the_post(); ?> <h3> <?php _e('All posts by'); ?> <?php echo get_the_author(); ?> <span class="arrows">&raquo;</span> </h3> <?php while (have_posts()) : the_post();?> You call the_post() to populate the regular ...


2

When using custom post types I got around this problem by using the following code. Of course you will need to put in the HTML for how you want it to display on your site. <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query(''); // Enter you query here ?> <?php while ($wp_query->...


2

I assume you are trying to show the role of the post's Author and not the current user viewing the author page. assuming you are inside the loop, do the following: //get the post author's ID $user_id = get_the_author_meta( 'ID' ); //assume we are in The Loop $user_obj = get_userdata( $user_id ); if( !empty( $user_obj->roles ) ){ foreach( $user_obj-...


2

Change: $user_roles = $current_user->roles; with $user = new WP_User( $user_id ); $user_roles = $user->roles; and the $user_id should e the actual user id who's role you are trying to get. Update, Sorry i just read the author template part so try this: //first get the current author whos page you are viewing if(isset($_GET['author_name'])) ...


2

How are you creating the author's link? If you put in your template: <?php the_author_posts_link(); ?> It will write the author's name and link for the current post. To modify the template for the author page, wordpress search for the following files in your theme's folder (in this order): author-{nicename}.php author-{id}.php author.php archive....


2

I just put a piece of code from author.php file of TwentyTwelve theme: <?php /* Queue the first post, that way we know * what author we're dealing with (if that is the case). * * We reset this later so we can run the loop * properly with a call to rewind_posts(). */ the_post(); ?> <header class="archive-header"> ...


2

You're going to want to use the author_template filter to process this. Just to clarify, the filter's "author" means all users, it appears. I'm not sure why. This will be called while the backend is deciding which template page to use when showing a user's profile on your site. You need to add an author-editor.php file and then filter to it if the user ...


2

If you use code similar to setup the rewrite rules: function ex_rewrite( $wp_rewrite ) { $feed_rules = array( 'author/?$' => 'index.php?author_page=author_page' ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; return $wp_rewrite; } // refresh/flush permalinks in the dashboard if this is changed in any way ...


2

You've already used sanitize_title once in you code. You need to use that in again, inside the wpse5742_author_link function. $link = str_replace( $author_nicename, sanitize_title($author_nickname), $link ); That should take care of the spaces. Another other option is to use urlencode but sanitize_title keeps things consistent. I (minimally) tested your ...


2

First get a list of the author posts then loop over the each post and get the terms used ex: function list_author_used_terms($author_id){ // get the author's posts $posts = get_posts( array('post_type' => 'custom_post_type_name', 'posts_per_page' => -1, 'author' => $author_id) ); $author_terms = array(); //loop over the posts and ...


Only top voted, non community-wiki answers of a minimum length are eligible