Join WhatsApp ChannelJoin Now

How To Get post_type Data in WordPress

Hi Dev,

Today, we will show you how to get post_type data in wordpress. This article will give you simple example of how to get post_type data in wordpress. Let’s discuss how to get post_type data in wordpress. In this article, we will implement a how to get post_type data in wordpress.

So let’s follow few step to create example of how to get post_type data in wordpress.

Step 1: All Post Data Get

<?php $loop = new WP_Query( array ( 'post_type' => 'post', 'orderby' => 'post_id', 'posts_per_page' =>'10') ); ?>

<?php while( $loop->have_posts() ): $loop->the_post(); ?>

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'full' ); ?>

  <article class="article_codeplaners">
    <div class="code_img">
        <a href="<?php the_permalink() ?>"><img src="<?php echo $url ?>" alt=""></a>
    </div>
    <div class="code_cont">
        <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
        <span></span>
    </div>
</article>   

<?php endwhile; wp_reset_query();?>

Step 2: Category Wise Post Get

 <?php $loop = new WP_Query( array ( 'post_type' => 'post', 'orderby' => 'post_id', 'cat' =>'2', 'posts_per_page' =>'10') ); ?>

    <?php while( $loop->have_posts() ): $loop->the_post(); ?>

    <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'full' ); ?>

    <article class="article_codeplaners">
    <div class="code_img">
        <a href="<?php the_permalink() ?>"><img src="<?php echo $url ?>" alt=""></a>
    </div>
    <div class="code_cont">
        <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
        <span></span>
    </div>
    </article>   

    <?php endwhile; wp_reset_query();?>

Step 3: offset Wise Post Get

<?php $loop = new WP_Query( array ( 'post_type' => 'post', 'orderby' => 'post_id',  'offset' => '2','posts_per_page' =>'10') ); ?>
                    
    <?php while( $loop->have_posts() ): $loop->the_post(); ?>

    <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'full' ); ?>

    <article class="article_codeplaners">
        <div class="code_img">
            <a href="<?php the_permalink() ?>"><img src="<?php echo $url ?>" alt=""></a>
        </div>
        <div class="code_cont">
            <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
            <span></span>
        </div>
    </article>   

<?php endwhile; wp_reset_query();?>

I hope it will assist you…

Recommended Posts