最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

WordPress does not find author pages in search

matteradmin9PV0评论

I have created a custom child theme based on twentytwelve. I assumed that searching for 'Addy' should return results, as I have an author named 'Addy'. Url is here: .

I have created a custom child theme based on twentytwelve. I assumed that searching for 'Addy' should return results, as I have an author named 'Addy'. Url is here: https://www.nvk-keramiek.nl.

Share Improve this question edited Nov 1, 2018 at 15:25 Mr. Hugo asked Nov 1, 2018 at 14:19 Mr. HugoMr. Hugo 1215 bronze badges 3
  • 1 WordPress search will only return posts and pages, never archives of any kind, and those searches will only search the post titles and content. So what you’re experiencing is the normal behaviour. – Jacob Peattie Commented Nov 1, 2018 at 14:39
  • This is not related to the theme. You should alter the search query if you want to find author archives. – fuxia Commented Nov 1, 2018 at 14:43
  • Okay.... so something like this? wordpress.stackexchange/questions/105168/… – Mr. Hugo Commented Nov 1, 2018 at 15:05
Add a comment  | 

1 Answer 1

Reset to default 1

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
// Get the results
$authors = $wp_user_query->get_results();
// Check for results
if ( ! empty( $authors ) ) { ?>
  <?php foreach ( $authors as $author ) {
  // get all the user's data
  $author_info = get_userdata( $author->ID );
  ?>
    <article class="post">
      <header class="entry-header">
        <h1 class="entry-title"><?php echo $author_info->display_name; ?></h1>
      </header>
      <div class="entry-content">
        <p><?php echo wp_trim_words( get_the_author_meta('description',$author_info->ID), 50, '...' ); ?></p>
        <a href="/author/<?php echo $author_info->user_nicename; ?>" class="arrowafter">Lees verder</a>
      </div>
    </article>
  <?php } ?>
<?php } ?>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far