admin管理员组文章数量:1130349
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
1 Answer
Reset to default 1I 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 } ?>
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
1 Answer
Reset to default 1I 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 } ?>
本文标签: WordPress does not find author pages in search
版权声明:本文标题:WordPress does not find author pages in search 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749213903a2333837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论