Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Custom Taxonomy is useful to exclude any item from blog/portfolio etc.
- Step 01 : Register this in functions.php
- function pages_taxonomy() {
- register_taxonomy(
- 'portfolio_cat', // this will be used in query.
- 'work', //Name of your custom post.
- array(
- 'hierarchical' => true,
- 'label' => 'Portofolio Category',
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'portfolio-category',
- 'with_front' => true
- )
- )
- );
- }
- add_action('init', 'pages_taxonomy');
- Step 02: Then call the custom taxonomy in any query like this:
- IF YOU USE SHORTCODE:
- $q = new WP_Query(
- array('posts_per_page' => 4, 'post_type' => 'work', 'portfolio_cat' => 'Featured')
- );
- IF YOU USE GLOBAL QUERY:
- <?php
- global $post;
- $args = array( 'posts_per_page' => 4, 'post_type'=> 'post', 'portfolio_cat' => 'Featured');
- $myposts = get_posts( $args );
- foreach( $myposts as $post ) : setup_postdata($post); ?>
- <?php
- $promotions_icon = get_post_meta($post->ID, 'promotions_icon', true);
- ?>
- // Put your content here
- <?php endforeach; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement