WordPress(ワードプレス)の「tax_query」と「meta_query」を併用して「OR」取得を実装
WordPress(ワードプレス)を使用して特定条件の記事のみ表示する際に、「tax_q…
カスタム投稿タイプは、独立したコンテンツを作りたい場合に便利なワードプレスの追加機能。
WordPress(ワードプレス)を長く使用していると一般的な投稿(お知らせ・新着情報)以外にも実績やお役立ち情報など、一般投稿とは切り分けたコンテンツの投稿が必要となる場合がある。
投稿カテゴリーを使って、投稿を切り分けるのもできるが、管理画面が一目でわかりにくいので、今回はカスタム投稿タイプを使って独自の投稿機能を設ける方法をメモ。
// カスタム投稿タイプの追加
add_action('init', 'create_post_type' );
function create_post_type(){
register_post_type('test', // 投稿タイプ名の定義
array(
'labels' => array(
'name' => __( '独自コンテンツ' ), // 表示する投稿タイプ名
'singular_name' => __( '独自コンテンツ' )
),
'supports' => array(
'title',
'editor',
'thumbnail',
'custom-fields',
'excerpt',
'author',
'trackbacks',
'comments',
'revisions',
'page-attributes'
),
'public' => true,
'menu_position' =>5,
'has_archive' => true,
'show_in_rest' => true, /* グーテンベルクを有効 */
)
);
//カテゴリタイプの設定(カスタムタクソノミーの設定)
register_taxonomy(
'testcat', //カテゴリー名(任意)
'test', //カスタム投稿名
array(
'hierarchical' => true,
'update_count_callback' => '_update_post_term_count',
'label' => '独自コンテンツのカテゴリー', //表示させる名前
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
)
);
//タグタイプの設定(カスタムタクソノミーの設定)
register_taxonomy(
'testtag', //タグ名(任意)
'test', //カスタム投稿名
array(
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
'label' => '独自コンテンツのタグ', //表示させる名前
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
)
);
}
WordPress(ワードプレス)を使用して特定条件の記事のみ表示する際に、「tax_q…
ワードプレスの投稿機能を利用して、様々な投稿をされる中で、デザインをしっかりとしたものに…
ワードプレスの投稿のカテゴリー機能を、目的ごとに使い分けたいというご要望があった際に、カ…