Skip to content

Instantly share code, notes, and snippets.

@hitsujixgit
Created July 9, 2014 02:06
Show Gist options
  • Save hitsujixgit/96763ddc953af3b45362 to your computer and use it in GitHub Desktop.
Save hitsujixgit/96763ddc953af3b45362 to your computer and use it in GitHub Desktop.
ショートコードでslugを指定して、投稿記事を表示するプラグイン
<?php
/*
Plugin Name: Include post
Plugin URI: http://wordpress.hitsuji.me
Description: ショートコードでslugを指定して、投稿記事を表示するプラグインです
Version: 1.0
Author: Hitsuji
Author URI: http://hitsuji.me/about-me/
*/
function include_post_shortcode($atts) {
extract(shortcode_atts(array('slug' => ''), $atts));
if ($atts['slug'] !== '' ) {
$args = array(
'name' => $atts['slug'],
'post_type' => 'post',
'post_status' => 'publish',
'numberposts' => 1,
);
$my_posts = get_posts($args);
if ($my_posts) {
$content = apply_filters( 'the_content', $my_posts[0]->post_content );
$content = str_replace( ']]>', ']]&gt;', $content );
echo $content;
}
}
}
add_shortcode('include_post', 'include_post_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment