Last active
March 26, 2017 10:00
-
-
Save nyankichi-n-n/58d27a8667c92301d7f6ff3bb02b1f19 to your computer and use it in GitHub Desktop.
[デモ会員サイト構築]9. カスタム投稿の記事をホームページの記事一覧、投稿者の記事一覧、RSSに追加
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 一行目はシンタックスハイライトするために追加しています。 | |
// rssにカスタム投稿記事も追加する | |
function mysite_feed_request($vars) { | |
if ( isset( $vars['feed'] ) && !isset( $vars['post_type'] ) ) { | |
$vars['post_type'] = array( | |
'post', | |
'travel', | |
'cake' | |
); | |
} | |
return $vars; | |
} | |
add_filter( 'request', 'mysite_feed_request' ); | |
// pri_get_postsを使って、ホームページにカスタム投稿を含める | |
// 投稿者の記事一覧にカスタム投稿を含める | |
function change_posts_per_page($query) { | |
/* 管理画面,メインクエリに干渉しないために必須 */ | |
if ( is_admin() || ! $query->is_main_query() ){ | |
return; | |
} | |
/* ホームページの場合、ポストタイプにカスタム投稿を含める */ | |
if ( $query->is_home() ) { | |
$query->set( 'post_type', array('post' ,'travel' ,'cake') ); | |
return; | |
} | |
/* 投稿者の記事一覧にカスタム投稿を含める */ | |
if (is_author() && $query->is_main_query() ) { | |
$query->set( 'post_type', array( 'post', 'travel', 'cake' ) ); | |
} | |
} | |
add_action( 'pre_get_posts', 'change_posts_per_page' ); | |
function my_search_filter($query) { | |
} | |
add_action( 'pre_get_posts','my_search_filter' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment