douli8428 2019-05-20 11:19
浏览 219

获取作者在wordpress中搜索的所有帖子

I hope you can help me with a problem that I can not solve. I'm fixing the search on my wordpress site to show me all the posts in which an author appears, as main author or coauthor.

case 'autores':
    $authors = implode( ',', eco_search_authors( $_GET['s'] ) );
    $query->set ( 'author', $authors );
    break;

The above code represents the filter I created to perform search by author.

/**
 * Search for authors.
 *
 * @param  string   $search_author  Expression to look for
 * @return array                    Array of author IDs
 */
function eco_search_authors( $search_author ) {

    $args = array (
        'search' => '*'. esc_attr( $search_author ) . '*',
        'fields' => 'ID',
        'meta_query' => array(
            'relation' => 'OR',
            array(
                'key'     => 'first_name',
                'value'   => $search_author,
                'compare' => 'LIKE'
            ),
            array(
                'key'     => 'last_name',
                'value'   => $search_author,
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'description',
                'value' => $search_author ,
                'compare' => 'LIKE'
            )
        )
    );

    // Create the WP_User_Query object
    $wp_user_query = new WP_User_Query($args);

    // Get the results
    $found_authors = $wp_user_query->get_results();

    return $found_authors;

}

This part of the code is the function created to search the articles with the author that was searched.

What happens is that the search does not show all the articles of the searched author nor the articles in which the same author appears as coauthor.

Question: Has anyone ever come across this issue?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题