Support » Plugins » Loop with Custom Post Type and Taxonomy

  • Okay. I’ve researched and tried every stupid little thing. I need one-on-one help now. I’m creating a custom post type and taxonomy, and I need some help figuring out exactly what to put where to make it work.

    I want to display one custom post type taxonomy (artwork) on a page via the loop, have 4 posts on the page at once, and have it paginate through the rest. I’ve been so stuck.

    Here’s my post type and taxonomy creation–which works. I just need help to figure out how to get this stupid loop and pagination to work.

    function portfolio_register() {
        $labels = array(
            'name' => _x('Portfolio', 'post type general name'),
            'singular_name' => _x('Portfolio Item', 'post type singular name'),
            'add_new' => _x('Add New', 'portfolio item'),
            'add_new_item' => __('Add New Portfolio Item'),
            'edit_item' => __('Edit Portfolio Item'),
            'new_item' => __('New Portfolio Item'),
            'view_item' => __('View Portfolio Item'),
            'search_items' => __('Search Portfolio Items'),
            'not_found' => __('Nothing found'),
            'not_found_in_trash' => __('Nothing found in Trash'),
            'parent_item_colon' => '',
        );
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'menu_position' => 5,
            'supports' => array('title', 'editor', 'thumbnail'),
            'menu_icon' => 'dashicons-art',
            'has_archive' => 'true'
        );
        register_post_type('portfolio', $args);
    }
    
    add_action('init', 'portfolio_register');
    
    function create_portfolio_taxonomies() {
        $labels = array(
            'name' => _x('Categories', 'taxonomy general name'),
            'singular_name' => _x('Category', 'taxonomy singular name'),
            'search_items' => __('Search Categories'),
            'all_items' => __('All Categories'),
            'parent_item' => __('Parent Category'),
            'parent_item_colon' => __('Parent Category:'),
            'edit_item' => __('Edit Category'),
            'update_item' => __('Update Category'),
            'add_new_item' => __('Add New Category'),
            'new_item_name' => __('New Category Name'),
            'menu_name' => __('Categories'),
        );
    
        $args = array(
            'hierarchical' => true, // Set this to 'false' for non-hierarchical taxonomy (like tags)
            'labels' => $labels,
            'show_ui' => true,
            'show_admin_column' => true,
            'query_var' => true,
            'rewrite' => array('slug' => 'categories'),
        );
    
        register_taxonomy('portfolio_categories', array('portfolio'), $args);
    }
    
    add_action('init', 'create_portfolio_taxonomies', 0);

    Thanks in advance!

  • The topic ‘Loop with Custom Post Type and Taxonomy’ is closed to new replies.