Creating Custom Post Types

<?php

function post_types () {
        register_post_type('events', array(
            'has_archive' => true,
            'public' => true,
            'labels' => array(
                'name' => 'Events',
                'add_new_item' => 'Add New Upcoming Event',
                'edit_item' => 'Edit Event',
                'all_items' => 'All Events',
                'singular_name' => 'Event'
            ),
            'menu_icon' => 'dashicons-calendar',
        ));
    }

    add_action('init', 'post_types');

?>

Creating a Custom Post Type with Events name.

Now WP_Query to pull data to Homepage for this post.

<?php
	$args = array(
								'posts_per_page' => '10',
								'post_type' => 'events'
			);
	$homepageEvents = new WP_Query($args);

							while($homepageEvents->have_posts()){
								$homepageEvents->the_post();
?>

Add a Comment