• Hello,
    I’ve created a custom post type named Events. I then added a taxonomy, Categories. I have one category called Fair.
    When I click on the Fair category no posts shows up. https://phpbeginner.org/category/fair/

    Here’s the code:

    <div class="main-content">
    	<div class="row">
    
        		<div class="content-box">
                	<span>Fair</span>
                </div><!--end. content-box-->
    
        		<div class="large-9 columns">
                	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                			<div class="events-row">
    								<?php if(get_field('date_block')): ?>
                                         <?php while(has_sub_field('date_block')): ?>
                                            <div>
                                                <span class="date-block">
                                                    <span><?php the_sub_field('dateblock_month'); ?></span>
                                                    <span><?php the_sub_field('dateblock_day'); ?></span>
                                                </span>
                                            </div>
                                        <?php endwhile; ?>
                                    <?php endif; ?>
    
                                    <div class="event">
                                        <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
                                        <?php the_excerpt(); ?>
                                    </div>
                            </div><!--end. events-row-->
                    <?php endwhile; endif; ?>
                </div><!--end. large-9 columns-->
    
    		<div class="large-3 columns lborder">
        		<?php get_sidebar(); ?>
    		</div><!--end. large-3 columns-->
    	</div><!--end. row-->
    </div><!--end. main-content-->

    I’ve been banging my head on this for two days, any help is much appreciated.
    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Can you create a gist or pastebin with the post type registration and the taxonomy registration.

    It is unlikely that it is going to show up at https://phpbeginner.org/category/fair/ since that would reference a post category. It should be using the post type slug like https://phpbeginner.org/events/categories/fair/.

    Thread Starter starlajay

    (@starlajay)

    I’m still unfamiliar with Github. I will look into it though.
    I’m guessing the correct way of doing it is to use a rewrite rule maybe?

    Here’s my code:

    //Add new post type for Events
    add_action('init', 'events_post');
    function events_post()
    {
    	$event_labels = array
    	(
    		'name' => _x('Events', 'post type general name'),
    		'singular_name' => _x('Event', 'post type singular name'),
    		'all_items' => __('All Events'),
    		'add_new' => _x('Add New Event', 'events'),
    		'add_new_item' => __('Add new event'),
    		'edit_item' => __('Edit Event'),
    		'new_item' => __('New event'),
    		'view_item' => __('View events'),
    		'search_items' => __('Search in events'),
    		'not_found' => __('No events found'),
    		'not_found_in_trash' => __('No recipes found in trash'),
    		'parent_item_colon' => ''
    	);
    
    	$args = array
    	(
    	  'labels' => $event_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', 'author', 'comments', 'thumbnail', 'excerpt', ),
    	  'taxonomies' => array('category'), //post_tag supports tags
    	  'has_archive' => true
    	);
    
    	register_post_type('events', $args);
    }

    Yes if you are sharing the post category tax you will have to create a rewrite rule.

    Thread Starter starlajay

    (@starlajay)

    Would the rewrite rule be better or is there another way of doing it?

    The other way would be to hook into the category queries and get both events and posts. I’m not sure if you want to show both on the same archive page or not though.

    Thread Starter starlajay

    (@starlajay)

    Nah I don’t want that…
    Ok if I use the rewrite rule, would I have to register it as a taxonomy?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom Post Type Taxonomies Slug isn't showing’ is closed to new replies.