bp_search_label_search_type_cpts( string $search_type_label )

Change the display text of custom post type search tabs.

Description

Change it from ‘cpt-movie’ to ‘Movies’ for example.

Parameters

$search_type_label

(string) (Required)

Return

(string)

Source

File: bp-search/plugins/search-cpt/index.php

function bp_search_label_search_type_cpts( $search_type_label ){
	/**
	 * search type is 'cpt-movie', 'cpt-book' etc.
	 * so removing 'cpt-' gives us the custom post type name
	 */

	//Return label from admin search items options
	$items = bp_search_items();
	if ( isset( $items[$search_type_label] ) ) {
		return $items[$search_type_label];
	}

	$pos = strpos( $search_type_label, 'cpt-' );
	if( $pos === 0 ){
		$cpt_name = str_replace( 'cpt-', '', $search_type_label );

		$cpt_obj = get_post_type_object( $cpt_name );
		if( $cpt_obj && !is_wp_error( $cpt_obj ) ){
			$search_type_label = $cpt_obj->label;
		}
	}

	$pos = strpos( $search_type_label, 'Cpt-' );
	if( $pos === 0 ){
		$cpt_name = str_replace( 'Cpt-', '', $search_type_label );

		$cpt_obj = get_post_type_object( $cpt_name );
		if( $cpt_obj && !is_wp_error( $cpt_obj ) ){
			$search_type_label = $cpt_obj->label;
		}
	}
	return $search_type_label;
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.