Showing posts with label Display posts from custom post type wordress. Show all posts
Showing posts with label Display posts from custom post type wordress. Show all posts

Monday, 2 November 2015

How to get posts from custom post type wordpress


How to get posts from custom post type wordress

Here i have given a simple example. I hope it helps you.

<?php get_header(); ?>

<?php
$args=array(
  'post_type' => 'product',
  'post_status' => 'publish',
  'posts_per_page' => -1
);
?>
<div id="content">

<?php
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <a href="<?php the_permalink() ?>" ><?php the_title(); ?> - <?php echo get_post_meta( get_the_ID(), 'price', true); ?></a>
        <?php
      endwhile;
    }
    wp_reset_query();
    ?>

</div>
<?php get_footer(); ?>