lkSuperboy
Posted on: 3 years ago

Using WP_Query with Custom Post Types

* Setup query to show the ‘services’ post type with ‘8’ posts.
* Output the title with an excerpt.


                                              $args = array(  
        'post_type' => 'services',
        'post_status' => 'publish',
        'posts_per_page' => 8, 
        'orderby’ => 'title', 
        'order’ => 'ASC', 
    );

    $loop = new WP_Query( $args ); 
        
    while ( $loop->have_posts() ) : $loop->the_post(); 
        print the_title(); 
        the_excerpt(); 
    endwhile;

    wp_reset_postdata();