Skip to content

Instantly share code, notes, and snippets.

@phucdohong96
Last active November 30, 2017 09:07
Show Gist options
  • Select an option

  • Save phucdohong96/08d2bbc076605772ffded12ca46c3c93 to your computer and use it in GitHub Desktop.

Select an option

Save phucdohong96/08d2bbc076605772ffded12ca46c3c93 to your computer and use it in GitHub Desktop.
Example Create Shortcode WordPress
<?php
function custom_loop_function( $atts ) {
ob_start();
$opts = shortcode_atts( array(
'type' => 'post_type_option',
), $atts );
$output = '';
$args = array(
'post_type' => $opts['type'],
'posts_per_page' => '10',
'order' => 'DESC',
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$id = get_the_ID();
$title = get_the_title();
$image = get_the_post_thumbnail($id,'full');
$excerpt = get_the_excerpt();
$link = get_permalink ();
$content = get_the_content ();
?>
<div>HTML Content</div>
<?php
endwhile;
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('custom_loop_shortcode', 'custom_loop_function');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment