“WPQuery -Suche Taxonomie” Code-Antworten

Suche nach Taxonomie WordPress -Abfrage

// We get a list taxonomies on the search box
function get_tax_by_search($search_text){

$args = array(
    'taxonomy'      => array( 'my_tax' ), // taxonomy name
    'orderby'       => 'id', 
    'order'         => 'ASC',
    'hide_empty'    => true,
    'fields'        => 'all',
    'name__like'    => $search_text
); 

$terms = get_terms( $args );

 $count = count($terms);
 if($count > 0){
     echo "<ul>";
     foreach ($terms as $term) {
       echo "<li><a href='".get_term_link( $term )."'>".$term->name."</a></li>";

     }
     echo "</ul>";
 }

}

// sample
get_tax_by_search('Foo');
Mountain Goat

WPQuery -Suche Taxonomie

//WP QUERY SEARCH TAXONOMY 
$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => 'my-taxonomy',
            'field' => 'slug',
            'terms' => 'my-term-slug',
        )
    )
);
gtamborero

Ähnliche Antworten wie “WPQuery -Suche Taxonomie”

Fragen ähnlich wie “WPQuery -Suche Taxonomie”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen