Skip Navigation

[Resolved] My website doesn't show any custom posts on search

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Cheikh KACFAH 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1247083

I am trying to:
Display custom post contents on search.php
Link to a page where the issue can be seen:
hidden link
I expected to see:
Customs posts as result (like few day ago). I manage relevansi plugin to display only a custom post, produce with toolset.
Instead, I got: Nothing, However $wp_query->found_posts in search.php seems working. the problem is when starting lines : while (have_posts ()): the_post () in search.php

#1247094

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

If you are using the theme's search.php template to output the search results then Toolset doesn't appear involved in any way other than using Types to register the custom post type.

Custom post types are not included in search results, you would need to manually intervene so that they are.

Typically you would do so by using the pre_get_posts filter and modifying the main query on the search archive page so that it also includes the post types you require.

(I'm not sure whether Relevanssi normally does this for you, you'd have to consult their documentation. We have an integration with Relevanssi, but that is for when you are using Views to output search results, but you are using the search.php theme template.)

You would want to add something like this:

function tssupp_filter_search_query($query) {
  if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_search) {
      $query->set('post_type', array( 'post', 'my-post-type', 'other-post-type' ) );
    }
  }
}
add_action('pre_get_posts','tssupp_filter_search_query');

You specify an array of post types to be included in the search.

Can you try that?

#1247150

the name of mu custom post is : "entreprise"

so, i added this code in my functions.php but i still need assistance :

function tssupp_filter_search_query($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', array( 'post', 'entreprise', 'other-post-type' ) );
}
}
}
add_action('pre_get_posts','tssupp_filter_search_query');

#1247175

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Can you try temporarily disabling all plugins except for Toolset Types and then try again and let me know if that works? It may be another plugin is interfering here.

#1247427

I did it without success

#1247475

I solved the issue by desactivating "toolset layout". Thank you!