yoast_get_primary_term_id

Get the primary term ID.

Description

(bool|int) yoast_get_primary_term_id( (string) $taxonomy = 'category', (null) $post = null ); 

Returns (bool|int)

Parameters (2)

0. $taxonomy — Optional. (string) => 'category'
The taxonomy to get the primary term ID for. Defaults to category.
1. $post — Optional. (null) => null
Post to get the primary term ID for.

Usage

  1. if ( !function_exists( 'yoast_get_primary_term_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yoast-seo/inc/wpseo-functions.php'; 
  3.  
  4. // Optional. The taxonomy to get the primary term ID for. Defaults to category. 
  5. $taxonomy = 'category'; 
  6.  
  7. // Optional. Post to get the primary term ID for. 
  8. $post = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = yoast_get_primary_term_id($taxonomy, $post); 
  12.  

Defined (1)

The function is defined in the following location(s).

/inc/wpseo-functions.php  
  1. function yoast_get_primary_term_id( $taxonomy = 'category', $post = null ) { 
  2. $post = get_post( $post ); 
  3.  
  4. $primary_term = new WPSEO_Primary_Term( $taxonomy, $post->ID ); 
  5. return $primary_term->get_primary_term();