Adds option to include Tainacan items in the default WP search results.

This commit is contained in:
mateuswetah 2020-08-12 11:06:58 -03:00
parent 82e6323019
commit 5ecbddeee1
2 changed files with 33 additions and 2 deletions

View File

@ -152,7 +152,6 @@ if ( ! function_exists( 'tainacan_setup' ) ) {
add_theme_support( 'custom-units' );
add_theme_support( 'editor-style' );
add_editor_style( 'editor-style.css' );
}
} // End if().
@ -185,6 +184,23 @@ function tainacan_customize_editor_css() {
}
add_action( 'admin_head', 'tainacan_customize_editor_css');
/**
* 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 tainacan_include_items_in_search_results( $query ) {
if ( get_theme_mod( 'tainacan_search_include_items', false ) ) {
if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
$query->set( 'post_type', array_merge( ['post'], $collections_post_types ) );
}
}
}
add_action( 'pre_get_posts', 'tainacan_include_items_in_search_results' );
/**
* Set the content width based on the theme's design and stylesheet.
*

View File

@ -125,7 +125,22 @@ function tainacan_customize_register( $wp_customize ) {
'type' => 'checkbox',
'settings' => 'tainacan_hide_search_input',
'section' => 'tainacan_header_settings',
'label' => __( 'Hide search icon and input', 'tainacan-interface' ),
'label' => __( 'Hide search icon and input', 'tainacan-interface' )
) );
// Includes tainacan itens on search results
$wp_customize->add_setting( 'tainacan_search_include_items', array(
'type' => 'theme_mod',
'default' => false,
'capability' => 'edit_theme_options',
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
) );
$wp_customize->add_control( 'tainacan_search_include_items', array(
'type' => 'checkbox',
'settings' => 'tainacan_search_include_items',
'section' => 'tainacan_header_settings',
'label' => __( 'Include tainacan itens on the search results list', 'tainacan-interface' ),
'description' => __( 'Toggle to include tainacan itens on the search results list. By default it only lists WordPress Posts and Pages. The items will be displayed with the same appearence of posts, with their title, thumbnail and description.', 'tainacan-interface' )
) );
/**