With below code working for searching with post title and post content. And also after installing plugin 'ACF: Better Search', the post is also searching from the ACF fields and give search result on search result div element.

But now I also want to search the post with Author Name and with other custom added author meta values.

[WordPress 4.9.2]

Tried 'WP Extended Search — WordPress Plugins' plugin but did not worked.

// ajax hook for searching custom post type

add_action( 'wp_ajax_search_cposttype', 'searchCposttypeByTerm' );
add_action( 'wp_ajax_nopriv_search_cposttype', 'searchCposttypeByTerm' );

function searchCposttypeByTerm() {
$wp_query = new WP_Query(array(
    's' => $_GET['searchTerm']));

while ($wp_query->have_posts()) : $wp_query->the_post();
echo '<pre>';
                echo '</pre>';


Please could you help me. It will be better without using plugin.


1 Answer 1


You can start with prepare information what you need using MySQL

SELECT * FROM `wp_usermeta` WHERE `meta_key` = "description"

For example, you can create the file with the prepared output of your custom query and then use jQuery * Ajax for your search box..

I've show you sample of json file:


$gm = array("results"  => array());
$loop = new WP_Query( array( 'post_type' => array('post', 'page'), 'post_status' => 'publish') );
if ( $loop->have_posts() ): while ( $loop->have_posts() ): $loop -> the_post();
    $tmp = array(
        "title" => get_the_title(),
        "url" => get_the_permalink(),
        "text" => get_the_excerpt()

echo json_encode($gm);

Unlikely, HERE in WP Query Author parameters you can grab only post related to author.

So the best solution is just simple querys to SQL and output it in custom php file. Then easily you can show this info in your searchbox:)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.