Custom Post Type not showing in main loop

I have created a custom post type ‘courses’ but it is not showing up when I do a var_dump of get_post_types(). here is my code.

add_action( ‘init’, ‘create_post_types’ );
function create_post_types() {
$courseargs = array(
‘labels’ => array(
‘name’ => ‘Courses’,
‘singular_name’ => ‘Course’,
),
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘courses’ ),
‘capability_type’ => ‘post’,
‘taxonomies’ => array( ‘category’ ),
‘has_archive’ => true,
‘hierarchical’ => false,
‘menu_position’ => null,
‘menu_icon’ => ‘dashicons-welcome-learn-more’,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’ )
);
register_post_type( ‘courses’, $courseargs );
}

// add the featured image thumbnail to the admin courses column
add_filter( ‘manage_courses_posts_columns’, ‘add_img_column’ );
add_action( ‘manage_courses_posts_custom_column’ , ‘manage_img_column’, 10, 2 );

// size the thumbnail
add_image_size( ‘admin-list-thumb’, 80, 80, false );

function add_img_column($columns) {
$columns = array(
‘cb’ => ‘<input type=”checkbox” />’,
‘title’ => ‘Title’,
‘author’ => ‘Author’,
‘categories’ => ‘Categories’,
‘tags’ => ‘Tags’,
‘comments’ => ‘<span class=”vers”><div title=”Comments” class=”comment-grey-bubble”></div></span>’,
‘featured_thumb’ => ‘Thumbnail’,
‘date’ => ‘Date’
);
return $columns;
}

function manage_img_column( $column, $post_id ) {
switch ( $column ) {
case ‘featured_thumb’:
echo ‘<a href=”‘ . get_edit_post_link() . ‘”>’;
echo the_post_thumbnail( ‘admin-list-thumb’ );
echo ‘</a>’;
break;
}
}

// Show posts of ‘post’, ‘page’ and ‘courses’ post types on home page
function add_my_post_types_to_query( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( ‘post_type’, array( ‘post’, ‘page’, ‘courses’ ) );
return $query;
}
add_action( ‘pre_get_posts’, ‘add_my_post_types_to_query’ );

var_dump(get_post_types());

This is what the var_dump gives me.

array(8) {
[“post”]=>
string(4) “post”
[“page”]=>
string(4) “page”
[“attachment”]=>
string(10) “attachment”
[“revision”]=>
string(8) “revision”
[“nav_menu_item”]=>
string(13) “nav_menu_item”
[“custom_css”]=>
string(10) “custom_css”
[“customize_changeset”]=>
string(19) “customize_changeset”
[“oembed_cache”]=>
string(12) “oembed_cache”
}

Any help would be greatly appreciated.

Read more here:: Custom Post Type not showing in main loop

Leave a Reply

Your email address will not be published. Required fields are marked *