Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using custom post type named "fotograf". I want to show every post's category with

<?php the_terms( $post->ID, 'fgaleri', '', ', ', '' ); ?>

But if I click category then it redirects me to index.php and shows everything in posts (not custom post type).

You can test it with open my web site link ( http://www.onurunwebsitesi.com/ )

Click to Tümünü Göster (Show All) and test it! After, click to Category: Atatürk, you will redirect to index.php , not archive-fotograf.php

I tried this too:

<?php the_terms( $wp_query->$post->ID, 'fgaleri', '', ', ', '' ); ?>

But after this, my loop stopped and shows nothing in results.

What sould I do? Thanks for your helps, in advance.

My codes:

archive-fotograf

<?php 
/**
 * Displays the Pagination in Custom loop
 *
 */
?>
<?php get_header(); ?>
<?php $aranan= $_GET['s']; 
$kategorim = intval($_GET['cat']);
$myterm = get_term( $kategorim, 'fgaleri' ); 
$myslug = $myterm->slug;
?>
<div id="content">
<?php
$temp = $wp_query; //save old query
$wp_query= null; //clear $wp_query
$rakam= 0;
//The query
$wp_query = new WP_Query();
$wp_query->query( array( 'post_type' =>'fotograf', 's' => $aranan, 'paged' => $paged, 'taxonomy' => 'fgaleri', 'fgaleri' => $myslug ) );
//The loop
?>
<div id="FGaleri_2"><div id="FGaleri_Ic"><div id="FGaleriBaslik">Fotoğraf Galerisi 
<form action="<?php echo get_bloginfo('wpurl'); ?>" id="searchformfoto" method="get" name="searchform">
<?php 
$args = array( 
'taxonomy' => 'fgaleri',
'show_option_none' => 'Kategori Seçin',
'hierarchical' => 1
); 
wp_dropdown_categories($args); 
?>
<div id="aramabolumufoto"><input name="s" id="sfoto" type="text" value=""/>
<input type="hidden" name="post_type" value="fotograf" /> 
<input type="hidden" name="fgaleri" value="<?php echo $myslug; ?>" /> 
<input id="searchsubmitfoto" type="submit" value="Ara"/></div>
</form>
</div><div class="FGaleri_Ic_2">
<?php while ($wp_query->have_posts()): $wp_query->the_post(); 
$rakam++;
?>
<div class="FGaleriItem2" style="<?php if ($rakam % 5 == 0 ) { ?>margin-right: 0px;<?php } ?>">
Category: <?php the_terms( $post->ID, 'fgaleri', '', ', ', '' ); ?>
<div class="ResimUst"><?php if (has_post_thumbnail()) { ?><a href="<?php the_permalink() ?>"><?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );$url2 = get_bloginfo('template_directory') . "/timthumb.php?src=" . $url . "&amp;w=100&amp;h=100&amp;zc=1"; ?><img src="<?php if(get_option('of_timthumb')=="true") { echo $url2; } else { echo $url; } ?>" alt="" title="" width="100" height="100" /></a><?php } ?></div><div class="ResimAlt"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php 
?>
</div></div><?php endwhile; ?></div></div></div><div class="clearboth"></div>
<?php if(function_exists('wp_pagenavi') ) {
 wp_pagenavi(); //function call for plugin pagination( wp pagenavi plugin)
}else{ ?>
 <div id="navigasyon">
      <span class="previous-entries"><?php next_posts_link('« Daha Eski Fotoğraflar'); ?></span>
  <span class="next-entries"><?php previous_posts_link('Daha Yeni Fotoğraflar »'); ?></span>
 </div>
<?php
}//endif
?>
<?php
wp_reset_postdata();
$wp_query = null; //Reset the normal query
$wp_query = $temp;//Restore the query

?>

</div><?php get_sidebar(); ?></div><?php get_footer(); ?>

functions.php

<?php
add_action( 'init', 'register_cpt_fotograf' ); 
function register_cpt_fotograf() { 
$labels = array( 
'name' => _x( 'Fotoğraflar', 'fotograf' ), 
'singular_name' => _x( 'Fotoğraf', 'fotograf' ), 
'add_new' => _x( 'Yeni Ekle', 'fotograf' ), 
'add_new_item' => _x( 'Yeni Fotoğraf Ekle', 'fotograf' ), 
'edit_item' => _x( 'Fotoğrafı Düzenle', 'fotograf' ), 
'new_item' => _x( 'Yeni Fotoğraf', 'fotograf' ), 
'view_item' => _x( 'Fotoğrafı Önizle', 'fotograf' ), 
'search_items' => _x( 'Fotoğraf Ara', 'fotograf' ), 
'not_found' => _x( 'Fotoğraf Bulunamadı', 'fotograf' ), 
'not_found_in_trash' => _x( 'Çöpte Fotoğraf Bulunamadı', 'fotograf' ), 
'parent_item_colon' => _x( 'Ana Fotoğraf:', 'fotograf' ), 
'menu_name' => _x( 'Fotoğraflar', 'fotograf' ), 
); 
$args = array( 
'labels' => $labels, 
'hierarchical' => false, 
'supports' => array( 'title', 'author', 'thumbnail', 'custom-fields', 'comments' ),
'public' => true, 
'show_ui' => true, 
'show_in_menu' => true, 
'show_in_nav_menus' => false, 
'publicly_queryable' => true, 
'exclude_from_search' => false, 
'has_archive' => true, 
'query_var' => true, 
'can_export' => true, 
'rewrite' => array('slug' => 'fotograflar'),
'capability_type' => 'post' 
); 
register_post_type( 'fotograf', $args ); 
} 

register_taxonomy("fgaleri", "fotograf", array("hierarchical" => true, "label" => "Fotoğraf Kategorileri", "singular_label" => "Fotoğraf Kategorisi", 'show_ui' => true, 'show_tagcloud' => false, "rewrite" => array('slug'=>'fkat')));

function mySearchFilter_0987($query) { 
$post_type = $_GET['post_type']; 
if (!$post_type) { 
    $post_type = 'post'; 
} 
$query->set('post_type', $post_type);
return $query; 
}; 

add_filter('pre_get_posts','mySearchFilter_0987');

// This filter will jump into the loop and arrange our results before they're returned

function limit_posts_per_archive_page() {   
if (is_post_type_archive()) { $limit = 20; } else { $limit = get_option('posts_per_page'); }        
set_query_var('posts_per_archive_page', $limit);
}
add_filter('pre_get_posts', 'limit_posts_per_archive_page');

if (!term_exists( 'Fotoğraf Galerisi', 'fgaleri') ) { 
wp_insert_term( 'Fotoğraf Galerisi', 'fgaleri',
array( 'description' => 'Fotoğraf Galerisi', 'slug' => 'fotogaleri' ) ); 
}

add_filter( 'request', 'my_request_filter' );
function my_request_filter( $query_vars ) {
if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
    $query_vars['s'] = " ";
}
return $query_vars;
}
?>
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.