WordPress does not find author pages in search

admin2025-06-06  0

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 } ?>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749213930a317317.html

最新回复(0)