Last active
May 13, 2021 12:18
-
-
Save cubdesign/1b96dfd2ef2b591f019b403eaa385c72 to your computer and use it in GitHub Desktop.
snow- monkeyで、再利用ブロックを使って、連載の記事に、連載の記事一覧を表示する方法
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 | |
/** | |
* 連載の記事に、連載の記事一覧を表示する | |
* | |
* 記事一覧は再利用ブロックを使用する。再利用ブロックのIDは、連載タグのカスタムフィールドから取得。 | |
*/ | |
add_action( | |
'snow_monkey_append_entry_content', | |
function() { | |
$post_id = get_the_ID(); | |
// 連載タグを取得 | |
$post_terms = get_the_terms( $post_id, 'series_tag' ); | |
if ( empty( $post_terms ) ) { | |
return ; | |
} | |
$term_id = $post_terms[0]->term_id; | |
if ( empty( $term_id ) ) { | |
return ; | |
} | |
// カスタムフィールドがら再利用ブロックのpost_idを取得する | |
$series_archive_list_wp_block_post_id = get_field("series_archive_list_wp_block_post_id",'series_tag'.'_'.$term_id); | |
if( empty($series_archive_list_wp_block_post_id) ) { | |
return ; | |
} | |
// 再利用ブロック | |
$block_post = get_post( intval($series_archive_list_wp_block_post_id) ); | |
if (empty($block_post)){ | |
return ; | |
} | |
if ($block_post->post_type !== "wp_block"){ | |
return ; | |
} | |
// 再利用ブロックのコンテンツを出力する | |
echo apply_filters( 'the_content',$block_post->post_content ); | |
} | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment