admin管理员组

文章数量:1122826

I am using wordpress. What I am doing is, that when the user enters anything then it will search from the post and will show the result.

I have added static content $_REQUEST['keyword']="team"; just for an example, Every time I get it No search found.

Any idea what is the issue?

function universalSearch( $atts ) {
    global $post;
    
    $_REQUEST['keyword'] = "leanding"; // it's just an example

    if ( ! empty( $_REQUEST['keyword'] ) ) {
        $args = array(
            'post_type' => 'post',
            's' => $_REQUEST['keyword'],
            'posts_per_page' => 5,
            'post_status' => 'publish',
        );
    }

    $result = new WP_Query( $args );
    
    if ( $result->have_posts() ) {
        while ( $result->have_posts() ) {
            $result->the_post(); 
            $tid = $result->ID;
            echo '<p><a href="' . get_permalink( $post->ID ) . '">' . get_the_title( $post->ID ) . '</a></p>';

        }
    } else {
        echo '<p><a href="javascript:void(0)">No search found.</a></p>';
    }
    
    wp_die();
}

I have check the wp query I am getting like this

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND (((wp_posts.post_title LIKE '{a30a32c58212e0e69da1fe713200b690a215277638267d3fc914587e000d21db}leanding{a30a32c58212e0e69da1fe713200b690a215277638267d3fc914587e000d21db}') OR (wp_posts.post_excerpt LIKE '{a30a32c58212e0e69da1fe713200b690a215277638267d3fc914587e000d21db}leanding{a30a32c58212e0e69da1fe713200b690a215277638267d3fc914587e000d21db}') OR (wp_posts.post_content LIKE '{a30a32c58212e0e69da1fe713200b690a215277638267d3fc914587e000d21db}leanding{a30a32c58212e0e69da1fe713200b690a215277638267d3fc914587e000d21db}'))) AND wp_posts.post_type = 'post' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.post_title LIKE

本文标签: pluginsWordpress search every time shows no search found even data exists