0

We have a Wordpress intranet using BuddyPress, bbPress etc..

From this article, I adjusted my theme's searchform.php to include:

<input type="hidden" name="post_type[]" value="docs" />
<input type="hidden" name="post_type[]" value="events" />
<input type="hidden" name="post_type[]" value="forums" />
<input type="hidden" name="post_type[]" value="posts" /> 
<input type="hidden" name="post_type[]" value="pages" /> 
<input type="hidden" name="post_type[]" value="topics" />

However, when we search for content written inside a Wordpress page, the search does not find this content.

This fact makes me wonder if the search is working properly or not.

The search results page reaches a URL like:

www.example.com/?post_type%5B%5D=docs&post_type%5B%5D=events&post_type%5B%5D=forums&post_type%5B%5D=posts&post_type%5B%5D=pages&post_type%5B%5D=topics&post_type%5B%5D=doc&s=document

I have tried including singular and plural but the issue remains:

<input type="hidden" name="post_type[]" value="docs" />
<input type="hidden" name="post_type[]" value="events" />
<input type="hidden" name="post_type[]" value="forums" />
<input type="hidden" name="post_type[]" value="posts" /> 
<input type="hidden" name="post_type[]" value="pages" /> 
<input type="hidden" name="post_type[]" value="topics" />
<input type="hidden" name="post_type[]" value="doc" />
<input type="hidden" name="post_type[]" value="event" />
<input type="hidden" name="post_type[]" value="forum" />
<input type="hidden" name="post_type[]" value="post" /> 
<input type="hidden" name="post_type[]" value="page" /> 
<input type="hidden" name="post_type[]" value="topic" />

Confused.

Help appreciated.

Update:

If I add

add_action( 'admin_footer', function() { print_r( get_post_types( [ 'exclude_from_search' => true ] ) ); } );

to functions.php, I receive the output:

Array
(
    [revision] => revision
    [nav_menu_item] => nav_menu_item
    [custom_css] => custom_css
    [customize_changeset] => customize_changeset
    [wp_router_page] => wp_router_page
    [forum] => forum
    [topic] => topic
    [reply] => reply
    [buddydrive-file] => buddydrive-file
    [buddydrive-folder] => buddydrive-folder
    [bp-email] => bp-email
    [bp_docs_folder] => bp_docs_folder
    [vc_grid_item] => vc_grid_item
    [bwg_gallery] => bwg_gallery
    [bwg_album] => bwg_album
    [bwg_tag] => bwg_tag
    [bwg_share] => bwg_share
    [tribe_venue] => tribe_venue
    [tribe_organizer] => tribe_organizer
    [deleted_event] => deleted_event
    [rtmedia_album] => rtmedia_album
    [thrive] => thrive
)
2
  • 3
    post and page are the built-in post types- singular, not plural.
    – Milo
    Commented May 15, 2017 at 5:13
  • Please provide some other code sample of this. So that we can debug better. Only this information is not enough for debugging this issue.
    – CodeMascot
    Commented May 15, 2017 at 5:44

1 Answer 1

1

The main search uses any custom post types (when you don't set post_type query var) so if you're missing public custom post types from that, then most likely those custom post types are registered with exclude_from_search as true.

Check if the plugins have filters to change that or try e.g. to override it with:

add_filter( 'register_post_type_args', function( $args, $post_type )
{
    if( in_array( $post_type, [ 'foo', 'bar' ], true ) && (bool) $args['public'] )
        $args['exclude_from_search'] = false;

    return $args;
}, 999, 2 );

where foo and bar are some custom post type slug examples that are public.

In bbpress forum and topic post types are registered public but with exclude_from_search as true (src). Also note it's singular and not forums and topics.

We can check for public and search excluded post types with:

$types = get_post_types( [ 'exclude_from_search' => true, 'public' => true ] );

that might contain an array like this one:

Array
(
    [foo] => foo
    [bar] => bar
)
8
  • Thanks birgire, I've searched the parent and child themes for exclude_from_search and only found one post type called Option Tree.
    – Steve
    Commented May 16, 2017 at 2:43
  • The custom post types are most likely registered in the plugins. I updated the answer. Check what kind of array print_r( $types ); gives @Steve
    – birgire
    Commented May 16, 2017 at 8:43
  • I downloaded all plugins, searched the plugins folder for exclude_from_search and found the following post types excluded from search: forum, topic, reply, spam, orphan, hidden status, bwg_gallery, bwg_album, bwg_tag, organizer, venue. I think this is okay, and should not be preventing me from finding the page content in the original post.
    – Steve
    Commented May 17, 2017 at 2:45
  • I created a blank index.php with <?php print_r( $types ); ?> and it produced an empty white page. :-P Help appreciated.
    – Steve
    Commented May 17, 2017 at 2:50
  • Try e..g. add_action( 'admin_footer', function() { print_r( get_post_types( [ 'exclude_from_search' => true ] ) ); } ); in your functions.php file and log in and check the admin footer and play with the parameters. @Steve
    – birgire
    Commented May 17, 2017 at 8:55

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.