Skip to content

Instantly share code, notes, and snippets.

@chrisgrabinski
Created January 26, 2015 10:45
Show Gist options
  • Save chrisgrabinski/f86fd46891ccd29551fd to your computer and use it in GitHub Desktop.
Save chrisgrabinski/f86fd46891ccd29551fd to your computer and use it in GitHub Desktop.
(Wordpress) Embed posts in an HTML-template using a shortcode
// [embedpost id="#"]
function embedpost_func( $atts ) {
$a = shortcode_atts( array(
'id' => 'Please add an "id" attribute',
), $atts );
// The post that is queried
$query = get_post($a['id']);
// Collect data from WP_POST
$type = $query->post_type;
$id = $query->post_name;
$name = $query->post_title;
$content = $query->post_content;
// Collect data from Types plugin
$custom = get_post_meta( $a['id'], 'wpcf-my_custom_field' );
ob_start();
include get_template_directory() . '/my-output-template.php';
return ob_get_clean();
}
add_shortcode( 'embedpost', 'embedpost_func' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment