How to loop through custom fields for a staff directory list in WordPress

I have a number of pages for staff members in my WP installation and each of these has additional custom fields for telephone, email, fax and classroom number.

I need to create a directory listing page which will pull all the custom fields from these pages depending on the department they are in.

Read More

It would be useful if pages had categories too but that does not seem to be the case, so my next option I guess would be to loop through a list of subpages under a parent pages, then extract the custom fields from these pages and order them alphabetically.

Could someone perhaps tell me if there is a better way to do this or show me what code snippet I would use to get this started please?

Related posts

Leave a Reply

1 comment

  1. Pages can have categories , you need to declare a custom taxonomy in your functions.php

    add_action('init','register_catalog_taxonomy');
    function register_catalog_taxonomy(){
      register_taxonomy(
          "department",
          array('page'),
          array(
            'hierarchical'=>true,
            "label"=>"Department",
            "singular_label"=>"Department",
            "rewrite"=>true,
            "capabilities"=>array('manage_terms','edit_terms','delete_terms','assign_terms')
            )
          );
    }
    

    you need to check the following page in the wordpress codec :

    register_taxonomy