Forums

List ALL Taxonomies for user selection (3 posts)

  1. EssexPaulo
    Member
    Posted 7 months ago #

    I am writing a "What's On" page so guests can enter details of events in their area.

    To help, I have added a new Taxonomy called 'town' in which I have added a list of towns so the user can select a town relevant to their post. I am also coding a sidebar entry system so the user can just enter information while looking at all posts and not having to go onto a new screen. (I don't allow users into the dashboard so they have to enter details from the front end).

    To lists all the entries for the 'town' taxonomy I am using:

    $terms = get_terms("town");
    $count = count($terms);
    if ( $count > 0 ){
        echo "
    <ul>";
        foreach ( $terms as $term ) {
          echo "
    <li>" . $term->name . "</li>
    "; }
        echo "</ul>
    "; }

    [Please post code snippets between backticks or use the code button.]

    However this only returns taxonomy terms for existing posts. I want to list all taxonomies so the users can select from a lists - Even if there are no events in their town.

    I've spent ages trying to find the answer to this but all the solutions only show taxonomy entries for any post which has a taxonomy associated with it. Any help would be great. I'm still pretty new to WordPress but am liking every minute of it.

    Thanks,
    Paul

  2. keesiemeijer
    moderator
    Posted 7 months ago #

    try it with: $terms = get_terms("town", "hide_empty=0");
    http://codex.wordpress.org/Function_Reference/get_terms

  3. EssexPaulo
    Member
    Posted 7 months ago #

    I am a fool - I've been searching for so long for this solution and it was really that simple.

    Thanks Keesiemeijer, I think I've read some of your posts on this forum so I'll follow closely for more tips.

    Much appreciated.
    P

Reply

You must log in to post.

About this Topic