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.
-
1WordPress 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 PeattieCommented 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.com/questions/105168/…– Mr. HugoCommented Nov 1, 2018 at 15:05
Add a comment
|
1 Answer
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 } ?>