• Resolved Jineu

    (@jineu)


    • Our Goal/Use Case: to have BuddyPress Docs appear in generic WP search results using wp_list_pages based on the user’s site access level or permissions. In short, extended generic search to pickup BP Docs that the user has access to.
    • Is there a way to make BuddyPress Docs available to users in generic WordPress search (based on the user profile, level, etc?)
    • Do we need to register the Buddypress Docs custom post type to get them picked up in generic WP search?

    We appreciate any ideas you can offer. BP Docs is excellent and we want to open it up to more users.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Jineu

    (@jineu)

    Self-solved. Add this into your themes functions.php:

    // Include Custom Post Types in Search
    /**
    * This function modifies the main WordPress query to include an array of
    * post types instead of the default ‘post’ post type.
    *
    * @param object $query The main WordPress query.
    */
    function my_include_custom_post_types_in_search_results( $query ) {
    if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
    $query->set( ‘post_type’, array( ‘post’, ‘page’, ‘bp_doc’) );
    }
    }
    add_action( ‘pre_get_posts’, ‘my_include_custom_post_types_in_search_results’ );
    //

    Plugin Author David Cavins

    (@dcavins)

    Excellent! Great job finding an answer!

    BP Docs are protected via an exclusionary WP_Query clause, so docs that the user shouldn’t see will be excluded from your search results. If you have hundreds of thousands of posts and docs, it may get to be a very slow query, though, so keep that in mind as your site grows.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP Search and BuddyPress Docs Post Type’ is closed to new replies.