WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get bookmark categories (4 posts)

  1. tkhobbes
    Member
    Posted 5 years ago #

    Hi all

    I want to get a list of all bookmark categories (i. e. category IDs) - similar to what is possible with "get_categories" for the post categories. Also, I need the corresponding name for each category ID.

    Reason is, I want to build a drop-down field to select bookmarks by category.

    I tried wp_list_categories('echo=0'), but this does not seem to return an array or something... and then I tried get_bookmarks - but I couldn't figure out how the array is built.... can someone help me, I am pretty sure that I am quite near to the solution...

  2. MichaelH
    Member
    Posted 5 years ago #

    Try this:

    <?php
      $taxonomy = 'link_category';
      $title = 'Link Category: ';
      $args ='';
      $terms = get_terms( $taxonomy, $args );
      if ($terms) {
        foreach($terms as $term) {
          if ($term->count > 0) {
            echo '<p>' . $title .' ID = '. $term->term_id . ' ' . $term->name . ' contains ' . $term->count . ' link(s). </p> ';
          }
        }
      }
    ?>
  3. tkhobbes
    Member
    Posted 5 years ago #

    Thanks - I solved this with other means, meantime, as the drop-down is not necessary any more. I set this to solved, in order for others to serve as reference. :)

  4. flyingkites
    Member
    Posted 4 years ago #

    I cut this down to

    <?php
    $taxonomy = 'link_category';
    $title = 'Link Category: ';
    $args ='';
    $terms = get_terms( $taxonomy, $args );
    if ($terms) {
    foreach($terms as $term) {
    if ($term->count > 0) {
    echo '<p>' . $term->name . ' </p> ';
    }
    }
    }
    ?>

    just to list the link categories. It is possible to make them clickable so you can go to a page showing that category's links?

Topic Closed

This topic has been closed to new replies.

About this Topic