1

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.

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. Nov 1 '18 at 14:39
  • This is not related to the theme. You should alter the search query if you want to find author archives.
    – fuxia
    Nov 1 '18 at 14:43
  • Okay.... so something like this? wordpress.stackexchange.com/questions/105168/…
    – JoostS
    Nov 1 '18 at 15:05
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 } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.