I am trying to making a shortcode for wordpress the point is to be able to buy tickets for a theatre, I cant make it to retrieve the data from my wordpress posts, I dont get anything back from the wordpress loop.
This code is located at the bottom of the functions.php in wordpress
The shortcode should be displayed in the homepage of http://iga.jpandroidpeter.com but as you can see there is no data displayed.
This is what I tried:
function teatro_func() {
if (have_posts()):
while (have_posts()) : the_post();
return
?>
<div class="teatro-all">
<?php the_post_thumbnail(); ?>
<h2 class="teatro-title"><?php the_title(); ?></h2>
<h4 class="teatro-date" href="#">custom field date will go here</h4>
<h4 class="teatro-date" href="#">custom field price will go here</h4>
<h4 class="teatro-date" href="#">custom field place will go here</h4>
<a class="teatro-buy" href="#">BUY TICKET</a>
<a class="teatro-buy" href="<?php the_permalink(); ?>">READ MORE</a>
</div>
<?php
endwhile;
endif;
}
add_shortcode('lorem', 'teatro_func');
Try Below code,
$args = array(
'posts_per_page' => -1,
'post_type' => 'post'
);
$query = new WP_Query( $args );
if( $query->have_posts() ):
while( $query->have_posts() ) : $query->the_post(); ?>
<div class="teatro-all">
Your fields goes here.....
</div>
<?php
endwhile;
else :
endif;