Skip to content

Instantly share code, notes, and snippets.

@asllanmaciel
Last active August 10, 2021 12:15
Show Gist options
  • Save asllanmaciel/9e4de3f4c59c1a0324ddcb049f2937b7 to your computer and use it in GitHub Desktop.
Save asllanmaciel/9e4de3f4c59c1a0324ddcb049f2937b7 to your computer and use it in GitHub Desktop.
<?php
function cpt_shortcode(){
$args = array(
'post_type' => 'at_biz_dir', // Custom Post Type
'posts_per_page' => -1,
//'orderby' => 'date', // we will sort posts by date
//'order' => $_POST['date'] // ASC or DESC
);
//Start variable to the content
$html = '';
$query = new WP_Query( $args );
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post();
//Get all metas
$meta = get_post_meta( get_the_ID() );
//Meta Fields
$thumbnail_id = get_post_meta( get_the_ID(), '_thumbnail_id', true );
$video = get_post_meta( get_the_ID(), '_video', true );
$address = get_post_meta( get_the_ID(), '_address', true );
$phone = get_post_meta( get_the_ID(), '_phone', true );
$email = get_post_meta( get_the_ID(), '_email', true );
$website = get_post_meta( get_the_ID(), '_website', true );
$excerpt = get_post_meta( get_the_ID(), '_excerpt', true );
//var_dump($meta);
$html.= '<div id="post-'.get_the_ID() .'" class="box-jogos box-campos col-lg-4 col-md-4 col-sm-12">';
$html.= '<div class="thumbnail">';
/* grab the url for the full size featured image */
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
/* link thumbnail to full size image for use with lightbox*/
$html.= '<a href="'.get_permalink(get_the_ID()).'">';
$html.= get_the_post_thumbnail(get_the_ID());
$html.= '</a>';
$html.= '</div>';
$html.= '<div class="title">'.get_the_title().'</div>';
$html.= '<div class="address"><i class="directorist-icon la la-map-marker"></i> '.$address.'</div>';
$html.= '<div class="phone"><i class="directorist-icon la la-phone"></i> '.$phone.'</div>';
$html.= '<div class="email"><i class="directorist-icon la la-envelope" aria-hidden="true"></i> '.$email.'</div>';
$html.= '<div class="website"><i class="directorist-icon la la-globe"></i> '.$website.'</div>';
$html.= '<div class="button"><a href="'.home_url().'/assista?quadra-campo='.get_the_ID().'"><button><i class="fa fa-eye" aria-hidden="true"></i> Ver Jogos</button></a></div>';
$html.= '</div>';
endwhile;
//Reset query
wp_reset_postdata();
endif;
return $html;
}
add_shortcode( 'cpt', 'cpt_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment