Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iamlucianojr/7fe2c06189bfc2d7e3023deb67acfd72 to your computer and use it in GitHub Desktop.
Save iamlucianojr/7fe2c06189bfc2d7e3023deb67acfd72 to your computer and use it in GitHub Desktop.
How to list custom post type and custom fields on WP
<?php
/*
Template Name: Event list
*/
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
$args = array( 'post_type' => 'event', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo the_meta();
echo '<div class="entry-content">';
$name = get_post_meta(get_the_ID(), 'wpcf-name');
var_dump($name[0]);
the_content();
echo '</div>';
endwhile;
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment