Home Forums General Issues query_posts not searching for text inside the post


query_posts not searching for text inside the post

  • Hi,

    I am new to ACF and new to PHP itself. Since we don’t have the resources to hire an expert, I have to solve this issue myself.

    We have a search function on the website in which the search results match a post-type with the searched term. My problem is, the search result looks for the term in the post title and the opening post text. It does not search for the term in the content in the ACFs. Below is the code. It would be great if you could help.

    				   $args = array(
    				   'post_type' => 'suited-trips',
    				   's'         => $_GET['s']
    					if ( have_posts() ) :
    					while(have_posts()) : the_post();
    					$img_id = get_post_thumbnail_id($post->ID);
    					$img_src = wp_get_attachment_image_src($img_id,full, true);?>
    			     <div class="<?php echo (++$j % 2 == 0) ? 'right-half-cont' : 'left-half-cont'; ?>">
    				    <div class="image-cont">
                            <a href="<?php the_permalink();?>"><img src="<?php echo etheme_get_resized_url($img_id, 557, 193, true);?>"></a>
    					<div class="list-text-cont">
    					     <a href="<?php the_permalink();?>"><h3><?php the_title(); ?></h3></a>
    						 <p><?php the_content(); ?></p>
    				 <?php echo (++$i % 2 == 0) ? '<div class="clear"></div>' : ''; ?>
    			    <?php  endwhile;
    				else :
                  	echo wpautop( 'Sorry, no posts were found' );
  • Hi @indian-outskirts

    If you want to filter the search based on the custom field, you can take a look at this page:

    That page is talking about archive pages, but the logic should be the same. You can set an attribute to the search URL and get it using the $_GET method. To query based on custom field, please take a look at this page:

    I hope this helps 🙂

  • If you want to search for custom fields you should use a plugin called Relevanssi (

    This plugin enables the standard wp search to look for terms inside custom fields also (it basically overrides the standard wp search).

    There is a setting in relevanssi that you can enable in order to make all custom fields searchable.

  • Hi @adser @indian-outskirts

    Yeah, Relevanssi is a great plugin to search the custom field value in the search string. Please take a look at this page too:


Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘query_posts not searching for text inside the post’ is closed to new replies.