I am using this code to first display each category. Problem is when i visit custom taxonomy category archive pages, its show all category post. I don't understand why? Please solve this code.
Custom post register and taxonomy register code (custom-posts.php)
:
add_action( 'init', 'thebdjob_theme_custom_post' );
function thebdjob_theme_custom_post() {
register_post_type( 'jobsposts',
array(
'labels' => array(
'name' => __( 'Jobs Posts' ),
'singular_name' => __( 'jobsposts' ),
'add_new_item' => __( 'Add New Jobs' ),
'edit_item' => __('Edit')
),
'public' => true,
'rewrite' => false,
'show_ui' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'query_var' => true,
'publicly_queryable' => true,
'supports' => array('title','editor','excerpt','custom-fields','comments','revisions','thumbnail','author','page-attributes'),
)
);
}
register_taxonomy(
'jobs_categories',
'jobsposts',
array(
'hierarchical' => true,
'label' => 'Jobs Categories',
'query_var' => true,
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'jobs_categories',
'with_front' => true
)
)
);
}
add_action( 'init', 'thebdjob_custom_post_taxonomy' );
And my archive.php
file code :
<?php global $post;
$args = array( 'posts_per_page' => 4, 'post_type'=> 'jobsposts', 'post_status'=> 'publish', 'orderby' => 'menu_order', 'order' => 'ASC', );
$myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php
$company_name= get_post_meta($post->ID, 'company_name', true);
$jobs_keyskills= get_post_meta($post->ID, 'jobs_keyskills', true);
$jobs_description= get_post_meta($post->ID, 'jobs_description', true);
$jobs_experience= get_post_meta($post->ID, 'jobs_experience', true);
$jobs_location= get_post_meta($post->ID, 'jobs_location', true);
?>
<div class="cat_post">
<div class="row">
<div class="col-cat-1">
<h4><a href="<?php echo get_permalink() ?>"><?php echo get_the_title(); ?></a></h4>
</div>
<div class="col-cat-1">
<div class="jtitle">
<?php echo $company_name; ?>
</div>
</div> <?php the_title(); ?>
<div class="col-cat-1">
<span class="stitle">Keyskills :</span>
<span itemore="description">
<?php echo $jobs_keyskills; ?>
</span>
</div>
<div class="col-cat-1">
<span class="stitle">Keyskills :</span>
<span itemore="description">
<?php echo $jobs_description; ?>
</span>
</div>
<div class="col-cat-1">
<span class="stitle">Location :</span>
<span itemore="description">
<?php echo $jobs_location; ?>
</span>
</div>
<div class="col-cat-1">
<span class="stitle">Experience :</span>
<span itemore="description">
1-3yrs
</span>
</div>
</div>
</div>
<?php endforeach; wp_reset_query(); ?>