You’re using a query inside a query at this point. Because of that you need to define global $post
at the top of your functions file so it has something to assign in the_post()
. Now that you have a $post
object you can replace all your test code with $post->attribute
:
//Recent post shortcode single
function mfbs_recent_post1x1($atts){
global $post;
$q = new WP_Query(
array( 'orderby' => 'date', 'posts_per_page' => '4')
);
$list="<div class="row mfbs1x1">";
while($q->have_posts()) : $q->the_post();
$title = $post->post_title;
$list .= '<div class="small-12 medium-12 large-12 columns">';
$list .= $title;
$list .= '<a href="' . get_permalink() . '">' ;
$list .= get_the_post_thumbnail($post->ID , 'medium', array( 'class' => 'alignleft' ) );
$list .= '<br>' . get_the_title() . '</a>' . '<br>' . get_the_excerpt() . '</div>';
endwhile;
wp_reset_query();
return $list . '</div>';
}
add_shortcode('foodrecentpost1x1', 'mfbs_recent_post1x1');