Switch language

wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren




term_exists [ WordPress Function ]

term_exists ( $term, $taxonomy = '', $parent = 0 )
Parameter:
  • (int|string) $term The term to check
  • (string) $taxonomy The taxonomy name to use
  • (int) $parent ID of parent term under which to confine the exists search.
Nutzt:
  • $wpdb
Gibt zurück:
  • (mixed) Returns 0 if the term does not exist. Returns the term ID if no taxonomy is specified and the term ID exists. Returns an array of the term ID and the taxonomy if the pairing exists.
Definiert in:



Check if Term exists.

Formerly is_term(), introduced in 2.3.0.

Source


<?php
function term_exists($term$taxonomy ''$parent 0) {
    global 
$wpdb;

    
$select "SELECT term_id FROM $wpdb->terms as t WHERE ";
    
$tax_select "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE ";

    if ( 
is_int($term) ) {
        if ( 
== $term )
            return 
0;
        
$where 't.term_id = %d';
        if ( !empty(
$taxonomy) )
            return 
$wpdb->get_row$wpdb->prepare$tax_select $where " AND tt.taxonomy = %s"$term$taxonomy ), ARRAY_A );
        else
            return 
$wpdb->get_var$wpdb->prepare$select $where$term ) );
    }

    
$term trimstripslashes$term ) );

    if ( 
'' === $slug sanitize_title($term) )
        return 
0;

    
$where 't.slug = %s';
    
$else_where 't.name = %s';
    
$where_fields = array($slug);
    
$else_where_fields = array($term);
    if ( !empty(
$taxonomy) ) {
        
$parent = (int) $parent;
        if ( 
$parent ) {
            
$where_fields[] = $parent;
            
$else_where_fields[] = $parent;
            
$where .= ' AND tt.parent = %d';
            
$else_where .= ' AND tt.parent = %d';
        }

        
$where_fields[] = $taxonomy;
        
$else_where_fields[] = $taxonomy;

        if ( 
$result $wpdb->get_row$wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s"$where_fields), ARRAY_A) )
            return 
$result;

        return 
$wpdb->get_row$wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s"$else_where_fields), ARRAY_A);
    }

    if ( 
$result $wpdb->get_var$wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where"$where_fields) ) )
        return 
$result;

    return 
$wpdb->get_var$wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where"$else_where_fields) );
}
?>

Beispiele [ wp-snippets.com ]

Top Google Suchergebnisse

Mehr ...

0 Nutzerkommentare

Noch keine. Sei der Erste!

Neu hinzufügen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics