PHP code example of tfrommen / meta-taxonomy
1. Go to this page and download the library: Download tfrommen/meta-taxonomy library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tfrommen / meta-taxonomy example snippets
/**
* Filters the taxonomy args.
*
* @param array $args Taxonomy args.
*/
add_filter( 'meta_taxonomy_args', function( $args ) {
// Turn the whole taxonomy UI invisible
$args[ 'show_ui' ] = FALSE;
return $args;
} );
/**
* Filters the taxonomy capabilities.
*
* @param string[] $capabilities Taxonomy capabilities.
*/
add_filter( 'meta_taxonomy_capabilities', function( $capabilities ) {
// Let meta taxonomy terms be deleted by admins only
$capabilities[ 'delete_terms' ] = 'manage_options';
return $capabilities;
} );
/**
* Filters the taxonomy description.
*
* @param string $description Taxonomy description.
*/
add_filter( 'meta_taxonomy_description', function() {
// Kill the description
return '';
} );
/**
* Filters the taxonomy labels.
*
* @param string[] $labels Taxonomy labels.
*/
add_filter( 'meta_taxonomy_labels', function( $labels ) {
// A little more horror, please...
$labels[ 'not_found' ] = 'ZOMG, no metas found!!1!!1!!oneone!!!1!eleven!1!';
return $labels;
} );
/**
* Filters the taxonomy name.
*
* @param string $name Taxonomy name.
*/
add_filter( 'meta_taxonomy_name', function() {
// Rename it
return 'meta_term';
} );
/**
* Filters the taxonomy object types.
*
* @param string[] $object_types Array of names of object types for the taxonomy.
*/
add_filter( 'meta_taxonomy_object_types', function( $object_types ) {
// Add the taxonomy for pages and a CPT, too
return array_unique( array_merge( (array) $object_types, array(
'page',
'my_cpt',
) ) );
} );
if ( has_meta_term( get_the_ID(), 'popular' ) ) {
// Do something
}