Advertisement
kobial8

Custom Taxonomy To exclude/Include Specific Item

Feb 15th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. Custom Taxonomy is useful to exclude any item from blog/portfolio etc.
  2.  
  3. Step 01 : Register this in functions.php
  4.  
  5.     function pages_taxonomy() {
  6.         register_taxonomy(
  7.             'portfolio_cat', // this will be used in query.
  8.             'work', //Name of your custom post.
  9.             array(
  10.                 'hierarchical' => true,
  11.                 'label' => 'Portofolio Category',
  12.                 'query_var' => true,
  13.                 'rewrite' => array(
  14.                     'slug' => 'portfolio-category',
  15.                     'with_front' => true
  16.                     )
  17.                 )
  18.             );
  19.     }
  20. add_action('init', 'pages_taxonomy');
  21.  
  22. Step 02: Then call the custom taxonomy in any query like this:
  23.  
  24. IF YOU USE SHORTCODE:
  25.    
  26.  $q = new WP_Query(
  27.         array('posts_per_page' => 4, 'post_type' => 'work', 'portfolio_cat' => 'Featured')
  28.         );
  29.  
  30. IF YOU USE GLOBAL QUERY:
  31.  
  32. <?php
  33. global $post;
  34. $args = array( 'posts_per_page' => 4, 'post_type'=> 'post', 'portfolio_cat' => 'Featured');
  35. $myposts = get_posts( $args );
  36. foreach( $myposts as $post ) : setup_postdata($post); ?>
  37.                
  38. <?php
  39. $promotions_icon = get_post_meta($post->ID, 'promotions_icon', true);
  40. ?>      
  41. // Put your content here
  42. <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement