PHP code example of kaiseki / wp-get-terms-by-post-type

1. Go to this page and download the library: Download kaiseki/wp-get-terms-by-post-type 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/ */

    

kaiseki / wp-get-terms-by-post-type example snippets


use Kaiseki\WordPress\GetTermsByPostType\HookRegistry;

return [
    'hook' => [
        'provider' => [
            HookRegistry::class,
        ],
    ],
];

$terms = get_terms([
    'taxonomy'    => 'category',
    'post_type'   => ['post', 'page'],   // string or list of strings
    'post_status' => ['publish'],        // optional; defaults to ['publish']
    'hide_empty'  => true,
]);

// Each returned term now carries a `count` of posts in the given post types.