I have a search field where a user can type in something to search a custom post type. This works okay if the word exists in the title but not in the content. Also, I want to include authors in the search so if they type in an author name, if they created a record for that post type it will also show the records. Is that possible?

$searchTerm = $_GET['s'];
$args = array(
    'post_type' => 'mycpt',
    's' => $searchTerm

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {

    while ( $the_query->have_posts() ) : $the_query->the_post(); 
        the_title() . '<br>';

} else {
        echo 'no posts found';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.