I'm trying to show my portfolios by category (i have 3 categories) On Dashboard i can create new categories/types but when i want list only "design category" on portfolio page "content not found"

these codes in function.php

function portfolio_s (){
    $labels = array(

    'name' => 'Portfolio',
    'add_new' => 'Add Item',
    'all_items' => 'all Item',
    'add_new_item' => 'Add new Item',
    'edit_item' => 'edit Item',
    'new_item' => 'new Item',
    'view_item' => 'view Item',
    'search_item' => 'search Item',
    'not_found' => 'No Items found',
    'not_found_in_trash' => 'No item',
    'parent_item_colon' => 'Parent Item',

    'labels' => $labels,
    'public' => true,
    'has_archive' => true,
    'publicly_gueryable' =>true,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'supports' => array(

    'exclude_from_search' => false
register_post_type( "portfolio", $args );
add_action( 'init', 'portfolio_s' );

function portfolio_taxonomies() {

    $labels = array(
    'name' => 'Types',
    'singular_name' => 'Type',
    'search_items' => 'Search Types',
    'all_items' => 'All Types',
    'parent_item' => 'Parent Types',
    'parent_item_colon' => 'Parent Types',
    'edit_item' => 'edit Type',
    'update_item' => 'update Type',
    'add_new_item' => 'Add new Product',
    'new_item_name' => 'All Types',
    'menu_name' => 'Types',

    $args= array(
    'hierarchical'          => true,
    'labels' => $labels,
    'show_ui' =>true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array('slug' => 'type')

    register_taxonomy('type', array('portfolio'), $args);
    add_action('init', 'portfolio_taxonomies');

portfolio file here.

<div class="row">

<?php   $query = new WP_Query( array( 'slug' => 'design' ) );?>

<?php if($query->have_posts()):?>   

<?php while($query->have_posts()) : $query->the_post();?>   

            <div class="col-md-3 referans-oge">

            <a href="<?php the_permalink();?>"><?php the_post_thumbnail('thumbnail-large', array('class'=>'img-fluid'));?></a>


<?php endwhile;?>       

<?php else:?>

Content not found

<?php endif;?>

1 Answer 1


Most of your code looks OK. But there is a major problem with your WP_Query in portfolio template. Your query looks like this:

<?php   $query = new WP_Query( array( 'slug' => 'design' ) );?>

And if you take a look at WP_Query docs, you'll see there is no parameter called slug. So it's pretty clear that it can't work.

If you want to display portfolio posts with given type, then your query should look like this:

$query = new WP_Query( array(
    'post_type' => 'portfolio',
    'posts_per_page' => -1,
    'tax_query' => array(
        array( 'taxonomy' => 'type', 'field' => 'slug', 'terms' => 'design' ),
) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.