0

今日初めてカスタム投稿タイプを使用しているので、無知を許してください。

プラグインによって事前定義されたカスタム投稿タイプを使用しています。ほとんどすべてのイベントカレンダープラグインは、カスタム投稿タイプを使用して「イベント」投稿タイプを設定しているようです。

通常の投稿に割り当てる通常のカテゴリを使用して、カスタムイベントの投稿に割り当てる方法があるかどうか疑問に思いました。

たとえば、私は通常の投稿に使用している「南東」のような地域カテゴリを持っていますが、このカテゴリをイベント投稿に割り当てて、人々が「南東」カテゴリのアーカイブを見るときに、そのカテゴリに関連付けられている通常の投稿とイベントの投稿を表示できます。

これは可能ですか?

事前に助けてくれてありがとう

4

3 に答える 3

2

単純:

add_action( 'init', 'myfuncxx'); function myfuncxx() {
    register_taxonomy_for_object_type( 'category', 'custom_postttt_typee' );
}
于 2015-04-15T17:26:36.037 に答える
0

WordPress関数を使用することをお勧めしregister_taxonomy_for_object_type()ます。テーマのfunctions.phpファイルに次のように入力します。

function add_categories_to_events() {
    register_taxonomy_for_object_type( 'post_tag', 'event' );
}
add_action( 'init', 'add_categories_to_events' );
于 2012-04-25T15:03:13.163 に答える
0

ここでコードと手順を使用しました: http ://wp.miragearts.com/allinone-event-calendar-events-blog-home-categories-tags/

このコードをfunctions.phpに追加すると、まったく同じ名前とスラッグで2つのカテゴリ(通常の投稿用とイベントカスタム投稿用)を作成すると、基本的に1つのカテゴリを持つのと同じになることがわかりました。

これは私のサイトを少し遅くしているかもしれないと思いますが、それが問題を引き起こすかどうかを判断するのは本当に時期尚早です。

これがfunctions.phpのコードのコピーです。

// Add this to your theme's functions.php
function edit_my_query($query) {
  // Modify category and tag listings to include ai1ec events and all uses of the same term
  //  across event and post taxonomies
  //  ie live-music or arts whether they are event or post categories
  // also include ai1ec events in blog home and feeds
  if ( ( is_home() || is_feed() || is_category() || is_tag() ) 
          &&  empty( $query->query_vars['suppress_filters'] ) ) {
    // The 'suppress_filters' test above keeps your menus from breaking
    $post_type = get_query_var('post_type');
    if($post_type && $post_type[0] != 'post') {
      $post_type = $post_type;
    } else {
      $post_type = array('post','ai1ec_event'); // add custom post types here
    }
    $query->set('post_type',$post_type);
    if (is_category() || is_tag()) {
    // Add custom taxonomies to category and tag pages
    if (is_category()) {
        $taxonomy1 = 'category';
        $taxonomy2 = 'events_categories';
      }
      if (is_tag()){
        $taxonomy1 = 'post_tag';
        $taxonomy2 = 'events_tags';
      }
      $queried_object = $query->get_queried_object();
      $slug = $queried_object->slug;
      $query->set('tax_query', array(
        'relation' => 'OR',
        array(
          'taxonomy' => $taxonomy1,  'field' => 'slug', 'terms' => $slug
        ),
        array(
          'taxonomy' => $taxonomy2, 'field' => 'slug', 'terms' => $slug
        )
      ));
    }
  }
}
add_action('pre_get_posts', 'edit_my_query');
于 2012-04-25T20:42:04.397 に答える