• Resolved ctuxboy

    (@ctuxboy)


    Hello,

    I made a custom taxonomy ‘geboortelijst’:

    if ( ! function_exists( 'geboortelijst_taxonomy' ) ) {
    
    // Register Custom Taxonomy
    function geboortelijst_taxonomy() {
    
    	$labels = array(
    		'name'                       => _x( 'Geboortelijsten', 'Taxonomy General Name', 'text_domain' ),
    		'singular_name'              => _x( 'Geboortelijst', 'Taxonomy Singular Name', 'text_domain' ),
    		'menu_name'                  => __( 'Geboortelijsten', 'text_domain' ),
    		'all_items'                  => __( 'Alle geboortelijsten', 'text_domain' ),
    		'parent_item'                => __( 'Parent iIem', 'text_domain' ),
    		'parent_item_colon'          => __( 'Parent Item:', 'text_domain' ),
    		'new_item_name'              => __( 'Nieuwe geboortelijst', 'text_domain' ),
    		'add_new_item'               => __( 'Nieuwe geboortelijst', 'text_domain' ),
    		'edit_item'                  => __( 'Bewerk geboortelijst', 'text_domain' ),
    		'update_item'                => __( 'Update geboortelijst', 'text_domain' ),
    		'view_item'                  => __( 'Bekijk geboortelijst', 'text_domain' ),
    		'separate_items_with_commas' => __( 'Verschillende lijsten scheiden door komma\'s', 'text_domain' ),
    		'add_or_remove_items'        => __( 'Geboortelijst toevoegen of verwijderen', 'text_domain' ),
    		'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
    		'popular_items'              => __( 'Populaire geboortelijsten', 'text_domain' ),
    		'search_items'               => __( 'Geboortelijst zoeken', 'text_domain' ),
    		'not_found'                  => __( 'Niet gevonden', 'text_domain' ),
    		'no_terms'                   => __( 'Geen lijsten', 'text_domain' ),
    		'items_list'                 => __( 'Geboortelijsten', 'text_domain' ),
    		'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
    	);
    	$args = array(
    		'labels'                     => $labels,
    		'hierarchical'               => true,
    		'public'                     => true,
    		'show_ui'                    => true,
    		'show_admin_column'          => true,
    		'show_in_nav_menus'          => false,
    		'show_tagcloud'              => false,
    		'query_var'                  => 'geboortelijst',
    	);
    	register_taxonomy( 'taxonomy', array( 'post' ), $args );
    
    }
    add_action( 'init', 'geboortelijst_taxonomy', 0 );
    
    }

    I would like listing all the terms from the custom taxonomy on a page. I find this code:

    // your taxonomy name
    $tax = 'post_tag';
    
    // get the terms of taxonomy
    $terms = get_terms( $tax, [
      'hide_empty' => false, // do not hide empty terms
    ]);
    
    // loop through all terms
    foreach( $terms as $term ) {
    
      // if no entries attached to the term
      if( 0 == $term->count )
        // display only the term name
        echo '<h4>' . $term->name . '</h4>';
    
      // if term has more than 0 entries
      elseif( $term->count > 0 )
        // display link to the term archive
        echo '<h4><a href="'. get_term_link( $term ) .'">'. $term->name .'</a></h4>';
    
    }

    With the variable post_tag the code works very well.
    Replacing the variable post_tag to geboortelijst, but nothing showing.

    How can i showing all the terms from geboortelijst ?

    Christophe

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    As of version 4.5.0, the syntax for get_terms() has changed, so older examples are going to be invalid going forward. All arguments now should be in a single array:

    $args = array(
       'taxonomy'=>'geboortelijst',
       'hide_empty'=> false,
    );
    get_terms( $args );
    // the rest of your code...

    Thread Starter ctuxboy

    (@ctuxboy)

    Hi, @bcworkz,

    Thanks for the advice. I change the code, but this was not the solution.
    I found the problem

    The taxonomy name in this case is taxonomy

    register_taxonomy( 'taxonomy', array( 'post' ), $args );

    Then changing the name geboortelijst in taxonomy

    $terms = get_terms( array(
        'taxonomy' => 'taxonomy',
        'hide_empty' => false,
    ) );

    Now it works!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List custom taxonomy’ is closed to new replies.