Advertisement
raselahmed7

Using Custom Taxonomy Wordpress

Jun 14th, 2013
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. =====================================================================================================
  2. // Register Custom Taxonomy
  3. =====================================================================================================
  4. <?php
  5. function pages_taxonomy() {
  6.     register_taxonomy(
  7.         'pages_cat',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
  8.         'page',          //post type name
  9.         array(
  10.             'hierarchical'      => true,
  11.             'label'             => 'Page Category',  //Display name
  12.             'query_var'         => true,
  13.             'rewrite'           => array(
  14.                 'slug'          => 'page-category', // This controls the base slug that will display before each term
  15.                 'with_front'    => false // Don't display the category base before
  16.                 )
  17.             )
  18.     );
  19. }
  20. add_action( 'init', 'pages_taxonomy');     
  21. <? 
  22.  
  23. =====================================================================================================
  24. // Custom Taxonomy Query
  25. =====================================================================================================
  26.  
  27. <?php
  28. global $post;
  29. $args = array( 'posts_per_page' => -1, 'post_type'=> 'staff', 'department_cat' => 'Commerical' );
  30. $myposts = get_posts( $args );
  31. foreach( $myposts as $post ) : setup_postdata($post); ?>
  32.                
  33.     // Your Post Content. Title, detail etc.
  34.                
  35. <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement