PHP code example of achttienvijftien / wp-primary-term

1. Go to this page and download the library: Download achttienvijftien/wp-primary-term 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/ */

    

achttienvijftien / wp-primary-term example snippets


add_filter( 'achttienvijftien_primary_term_taxonomies', function( $taxonomies ) {
    $taxonomies[] = 'category';
    $taxonomies[] = 'post_tag';
    return $taxonomies;
} );

if ( has_primary_term( 'category', $post_id ) ) {
    // ...
}

$term_id = get_primary_term_id( 'category', $post_id );

$term = get_primary_term( 'category', $post_id );
if ( $term instanceof \WP_Term ) {
    echo esc_html( $term->name );
}

add_filter( 'achttienvijftien_primary_term_use_fallback', '__return_false' );

yarn lint:js && yarn lint:php