I’m working on a project where I need to display a list of my custom post, just like with categories. I’ve made a custom post type (called “videoer”) in my functions.php:
function register_rc() { // A unique name for our function
$labels = array( // Used in the WordPress admin
'name' => _x('Videoer', 'post type general name'),
'singular_name' => _x('Video', 'post type singular name'),
'add_new' => _x('Add New', 'Video'),
'add_new_item' => __('Add New Video'),
'edit_item' => __('Edit Video'),
'new_item' => __('New Video'),
'view_item' => __('View Video '),
'search_items' => __('Search Videos'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash')
);
$args = array(
'labels' => $labels, // Set above
'public' => true, // Make it publicly accessible
'hierarchical' => true, // No parents and children here
'menu_position' => 5, // Appear right below "Posts"
'has_archive' => 'resources', // Activate the archive
'supports' => array('title','editor','comments','thumbnail','custom-fields'),
'taxonomies' => array('category', 'post_type'),
'public' => true,
'show_ui' => true,
'exclude_from_search' => true,
'query_var' => true,
);
register_post_type( 'videoer', $args );
}
This works well in the wordpress admin area, and i can also display the posts correctly. I have given each post a category called videoer
(the same name as the costum post type). Now if I want display all the post under the category videoer
I get nothing.
I have tried this on my video-category.php
:
<?php $loop = new WP_Query( array( 'post_type' => 'videoer', 'posts_per_page' => 100 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_post_thumbnail(); ?>
<h3><?php the_title() ?></h3>
<a href="<?php the_permalink() ?>">Read More</a>
<?php endwhile; ?>
Any advice is welcome!
videoer
post type will have a post archive atexample.com/videor
that lists allvideoer
postsvideoer_category
. Use the rewrite option on registration to change it to category and you’ll be able to have archives such asexample.com/videor/category/<term name here>/
taxonomy-videoer_category.php
template in your themesingle-videoer.php
videoer
is a fiddly name ( it isn’t a real english word ), perhaps you should rename it to video, or if you’re referring to the person who shoots the film, ‘Producer’?>
and put<?php
on the next line if there’s no HTML inbetween, it just makes it harder to read and easy to make silly mistakes