Created
January 26, 2015 10:45
-
-
Save chrisgrabinski/f86fd46891ccd29551fd to your computer and use it in GitHub Desktop.
(Wordpress) Embed posts in an HTML-template using a shortcode
This file contains hidden or 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
// [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