wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
term_exists [ WordPress Function ]
term_exists ( $term, $taxonomy = '', $parent = 0 )
| Parameter: |
|
| Nutzt: |
|
| Gibt zurück: |
|
| 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 ( 0 == $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 = trim( stripslashes( $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 > 0 ) {
$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
- Function Reference/term exists « WordPress Codex
Description. Check if a given term exists and return the term ID, a term object, or 0 (false) if the term doesn't exist. Usage. <?php term_exists( $term, $taxonomy, ...
codex.wordpress.org - term_exists() | Rachel Carden
term_exists(). This WordPress function requires the CPT-onomy class. Description; Usage; Parameters; Return Values; Related Functions; WordPress Codex ...
rachelcarden.com - php - wordpress term exists condition not working? - Stack Overflow
Check your else part, Should be: if ( term_exists('term', 'pdf')) { echo 'PDF' ; } else if ( term_exists( 'term', 'ppt')) { echo 'PPT' ; } else { echo 'MOV' ; } ...
stackoverflow.com - term_exists() WordPress function reference, arguments and source ...
term_exists(). Check if Term exists. Returns the index of a defined term, or 0 ( false) if the term doesn't exist. Formerly is_term(), introduced in 2.3.0.
queryposts.com
Nutzerduskussionen [ wordpress.org ]
- iyamdman on "Can you use term_exists from with in Javascript loop?"
- iyamdman on "term_exists not working in Javascript"
- stitch1z on "Call custom header.php into custom post type category / term_exists issues"
- Harry on "Call custom header.php into custom post type category / term_exists issues"
- stitch1z on "Call custom header.php into custom post type category / term_exists issues"
- Harry on "Call custom header.php into custom post type category / term_exists issues"
- stitch1z on "Call custom header.php into custom post type category / term_exists issues"
- Harry on "Call custom header.php into custom post type category / term_exists issues"
- Harry on "Call custom header.php into custom post type category / term_exists issues"
- stitch1z on "Call custom header.php into custom post type category / term_exists issues"