I'm developing an website that I didn't built the foundation for. When I try to implement a simple search query I just get nothing in response. There is no errors showing up in normal php error reporting. The only thing showing is complete blank result. If I turn on debug.log I don't get any returns from WP.

This is the code i'm running:

$args = array(
's' => 'test',
'post_type' => 'posts'
// The Query
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
//inside the loop

// Reset Post Data

If I run it without the 's' => 'test', parameter I get results returned. I tried different post types, different search queries etc... Everything works as soon as I remove the s parameter.

I run the query on a custom post type single page.

What could be the problem? And how do I debug it? Can't find any clue to what is wrong.

  • 1
    "I run the query on a custom post type single page." - in your example you run it on posts, can you post the actual $args? Does your CPT even have searchable fields (I believe title and content) filled? – kero Dec 18 '18 at 10:41
  • Kero’s point about searchable fields is important. If your custom post type’s content is all stored in custom fields then they won’t be returned in search. – Jacob Peattie Dec 18 '18 at 11:18
  • The first thing for debugging is to disable all plugins and switch to a default theme. Second, check exclude_from_search parameter where you register the custom post type (and other parameters as well). – Max Yudin Dec 18 '18 at 11:20
  • This is the query i'm running, what I meant by "I Run the query on a custom post type single page" is that I am running this exact query on a template page for a custom post type. So the query doesn't even work for normal post types... I will try look into your suggestions about disable plugins and looking for exclude_from_search. Thanks! – galengodis Dec 22 '18 at 8:07

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.