I have created shortcode for posts, now point is i need to shortcode post in post/page which works. Example i embed post2 in post1 and when i visit post1 i see that post2, but when i embed post1 in page1 i dont see post2
This is code i have written so far.
<?php
function getPostShortcode( $atts, $content = '' ) {
extract( shortcode_atts( array(
'id' => '',
'title' => ''
), $atts, 'post_shortcode' ) );
if ( empty( $atts['id'] ) )
return;
$loop = new WP_Query( array(
'post_type' => 'post',
'p' => $atts['id']
) );
ob_start();
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
$desc = ! empty( $atts['desc'] ) ? $atts['desc'] : get_the_content();
?>
<div class="post-single-shortcode-aka">
<h2><a href="#"><?php echo $title; ?></a></h2>
<p><?php echo $desc; ?></p>
</div>
<?php
endwhile;
wp_reset_postdata();
}
return ob_get_clean();
}
add_shortcode( 'post_shortcode', 'getPostShortcode' );
?>
global $post;before your WP Query. Please then addwp_reset_queryat the end. - wbdlc