Last active
September 28, 2018 19:57
-
-
Save hadamlenz/63de11374025b1c36b0ed00af9cbe86d to your computer and use it in GitHub Desktop.
proposed class for adding different taxonomies into the search tag interface on search iq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* If this file is called directly, abort. | |
*/ | |
if ( !defined( 'ABSPATH' ) ) { | |
die( 'Direct access is forbidden.' ); | |
} | |
class SearchIQ{ | |
function __construct(){ | |
add_filter( 'searchiq_add_tags', array( $this, 'searchiq_add_tags'), 10, 2 ); | |
add_action( 'init', array($this, 'add_search_tag_taxonomy'), 0 ); | |
} | |
public function searchiq_add_tags( $tags, $post ){ | |
$terms = get_the_terms( $post, 'search_tag'); | |
if( !empty( $terms ) ){ | |
foreach( $terms as $term ){ | |
$tags[] = $term->name; | |
} | |
} | |
return $tags; | |
} | |
function add_search_tag_taxonomy() { | |
$labels = array( | |
'name' => _x( 'Search Tags', 'Taxonomy General Name', 'text_domain' ), | |
'singular_name' => _x( 'Search Tag', 'Taxonomy Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Search Tag', 'text_domain' ), | |
'all_items' => __( 'All Search Tags', 'text_domain' ), | |
'parent_item' => __( 'Parent Search Tag', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Search Tag:', 'text_domain' ), | |
'new_item_name' => __( 'New Search Tag Name', 'text_domain' ), | |
'add_new_item' => __( 'Add New Search Tag', 'text_domain' ), | |
'edit_item' => __( 'Edit Search Tag', 'text_domain' ), | |
'update_item' => __( 'Update Search Tag', 'text_domain' ), | |
'view_item' => __( 'View Search Tag', 'text_domain' ), | |
'separate_items_with_commas' => __( 'Separate search tags with commas', 'text_domain' ), | |
'add_or_remove_items' => __( 'Add or remove search tags', 'text_domain' ), | |
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ), | |
'popular_items' => __( 'Popular Search Tags', 'text_domain' ), | |
'search_items' => __( 'Search Search Tags', 'text_domain' ), | |
'not_found' => __( 'Not Found', 'text_domain' ), | |
'no_terms' => __( 'No search tags', 'text_domain' ), | |
'items_list' => __( 'Search Tags list', 'text_domain' ), | |
'items_list_navigation' => __( 'Search Tags list navigation', 'text_domain' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => false, | |
'show_tagcloud' => true, | |
'rewrite' => false, | |
'show_in_rest' => true, | |
); | |
register_taxonomy( 'search_tag', array( 'post', 'page' ), $args ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add
$tags = apply_filters( 'searchiq_add_tags', $tags, $post);
to library/core.php on line 1021