I want to display five post titles of a specific author using $curauth;
I had a snippet of code that used to work just fine, but with some WordPress update it stopped working and I’m not sure why or how to fix it.
My old, formerly flawlessly working code looks like this:
<ul><?php query_posts('&author='.$curauth->ID.'showposts=5'); if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> am <?php the_time('d.m.Y'); ?></li>
<?php endwhile;?>
</ul>
<a href="<?php echo get_author_posts_url($authid); ?>?allposts=true">all posts by <?php echo $curauth->first_name; ?> →</a>
<?php else: ?>
<li><?php _e('No posts found.'); ?></li>
</ul>
<?php endif; ?>
Now, it always returns “No posts found”.
When checking the documentation of $query_posts I learned that it’s not recommended to use it anymore, but I don’t know what the alternative is and how to make this work again.
Any ideas? Thanks a lot!
]]><?php get_header(); ?>
<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
?>
<div id="primary">
<div id="content" role="main">
<div id="profil">
<p>Etage <?php echo $curauth->etage; ?> Atelier <?php echo $curauth->numero_datelier; ?></p>
<h1 class="entry-title"><p><?php echo $curauth->display_name; ?></p></h1>
<p><?php echo $curauth->designation; ?></p>
<p><?php echo $curauth->description; ?></p>
<?php
$author_id = get_the_author_meta( 'ID' );
$image_resident = get_field('image_resident', 'user_'. $author_id ); // image field, return type = "Image Object"
?>
<img src="<?php echo $image_resident['url']; ?>" alt="<?php echo $image_resident['alt']; ?>" />
<p><a>user_url; ?>"><?php echo $curauth->user_url; ?></a></p>
<p><a>user_email; ?>"><?php echo $curauth->user_email; ?></a></p>
Everything works (some are custom fields) except the Image.
Any idea ?
Thank you.
f
I’m kinda newbie. I’m having trouble with author’s slug in my site.
I don’t know if it’s caused by authoravatars plugin or if there’s something wrong with any $curauth variable used in my theme.
All the user profile links point to /root?author_name instead of pointing to the correct /root/?author=[id]
You can check this down here:
The site: https://www.uff.br/ppgcom/novosite/
A user profile: https://www.uff.br/ppgcom/novosite/?author=3
Anyone can help me?
]]>I have searched high and low with no avail. There are results for each point separately, but nothing that brings it all together.
I found this function that fetches custom post type names for $curauth and displays them, maybe there is a way to tailor it to my request.
function get_author_post_types( $author_id = false ) {
$results = array();
if ( $author_id ) {
$post_types= get_post_types( array( 'public' => true ), 'names', 'and' );
$post_types = array_keys( $post_types );
$sql = array();
global $wpdb;
$sql[] = "SELECT DISTINCT post_type FROM $wpdb->posts WHERE post_author = %d AND (post_status = 'publish') AND post_type IN(".implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ).")";
$sql[] = $author_id;
$sql = array_merge( $sql, $post_types );
$query = call_user_func_array( array( $wpdb, 'prepare' ), $sql );
$results = $wpdb->get_results( $query );
if ( $results )
$results = wp_list_pluck( $results, 'post_type' );
}
return $results;
I am seriously desperate, and would very much appreciate any help or direction with this.
Thanks in advance.
]]>anyone have a pointer?
<!– This sets the $curauth variable –>
<?php
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
?>
<p>This is <?php echo $curauth->nickname; ?>'s page</p>
<!– The Query–>
<?php
$args = array(
'author' => '$curauth->ID',
'post_type' => 'competitor',
'meta_key' => 'average',
'orderby' => 'meta_value_num',
'showposts' => 10,
);
$the_query = new WP_Query( $args );
?>
<!– The Loop –>
<?php while ( $the_query->have_posts() ) :
$the_query->the_post(); ?>
<?php
$average = get_post_meta(get_the_ID(), 'average', true);
// check if the custom field has a value
if($average != '') {
echo ($average)." <br />";
}
?>
<?php endwhile; ?>
<!– End Loop –>
]]>[_post_author_email]
doesn’t work on the author.php if you don’t wrap it in the loop and Contact Form 7 Dynamic Text Extension writes the recipient in the html-code.
So I tried to modify the plug-in by editing the compose_mail function in classes.php.
I changed the line
$recipient = $this->replace_mail_tags( $mail_template['recipient'] );
to
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $_GET['author_name']) : get_userdata($_GET['author']);
$recipient = $curauth->user_email;
and to
global $wp_query;
$postquery = $wp_query->get_queried_object();
if ($postquery instanceof WP_User) {
$the_email = $postquery->user_email;
}
else {
$the_email = get_the_author_meta( 'user_email' );
}
$recipient = $the_email;
But without luck. I’m not sure if you tolerate some alterations, but if you do so, I hope you could tell me what I’m missing.
]]>I am a newbie on wordpress and php and I have my mind blowing because I am trying to find a way to compile this code that I found here…
<?php
global $wp_query;
$curauth = $wp_query->get_queried_object();
$post_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '" . $curauth->ID . "' AND post_type = 'post' AND post_status = 'publish'");
?>
<h2>Post Count: <?php echo $post_count; ?></h2>
My goal is to show the count of published posts foreach custom post_type in author.php and I found a way to do it but this is not the right way. You can see my code here https://pastebin.com/6cSxs4th.
How can I compile this?
]]>The reason for this is because I have a number of businesses that have different staff inputing posts on their companies behalf and each author is registred under a different username(auhorname).
In order for their posts to be listed under the same business name, each author for that company has been instructed to add their company name as their nickname and for that to be used as their display name.
Hope that makes sense.
By doing this all auhtors from the same company are able to input their posts and have all posts come up under the company name.
I want the option display all posts by that compnay rather than all posts by one author
Any ideas? Is it even possible?
]]>This will take them them to a page where all the authors posts are listed in the loop and then I’m using:
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
to pull in the author info before the loop at the top of the page.
I’m curious what the PHP code is I need to do an if/else statement on this so that if the author has a bio, it would display text that reads “Displaying X number of posts by Author’s Name” plus the bio, if not, it would just display text that reads, “Displaying X number of posts by Author’s Name” without the bio.
Any help on this would be great. Thanks!
]]>All I want to do is put some information about the author on top of sidebar.php when a single entry is shown
Setting up a page for authors is not a problem (using $curauth).
However… how can I display this author information in the sidebar?
Putting this in sidebar.php doesn’t work:
<?php if (is_single()) : ?>
<h3>About the author</h3>
<p><?php echo $curauth->display_name; ?> wrote this</p>
<?php endif; ?>
As shown in The Codex, I called this before (still in sidebar.php):
<?php if(get_query_var(‘author_name’)) : $curauth = get_userdatabylogin(get_query_var(‘author_name’)); else : $curauth = get_userdata(get_query_var(‘author’)); endif; ?>
Putting this into header.php doesn’t work either.
Any help?
]]>