This code is going into a sample Plugin I am creating as a test using CPT and print them to a Page.
I have been trying to get print_r() to give me an object. The custom post types are posting - verified. The data is being stored in MySQL - verified. Thus the post type is registering.
Please provide me with a new set of eyes to tell me what I am missing in my query.
add_action('init', 'all_custom_post_types');
function all_custom_post_types() {
$types = array(
// Pledge Items
array('the_type' => 'testimonial',
'single' => 'Testimonial',
'plural' => 'Testimonials'));
foreach ($types as $type) {
$the_type = $type['the_type'];
$single = $type['single'];
$plural = $type['plural'];
$labels = array(
'name' => _x($plural, 'post type general name'),
'singular_name' => _x($single, 'post type singular name'),
'add_new' => _x('Add New', $single),
'add_new_item' => __('Add New '. $single),
'edit_item' => __('Edit '.$single),
'new_item' => __('New '.$single),
'view_item' => __('View '.$single),
'search_items' => __('Search '.$plural),
'not_found' => __('No '.$plural.' found'),
'not_found_in_trash' => __('No '.$plural.' found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'supports' => array('title','editor','thumbnail','custom-fields','excerpt'));
register_post_type($the_type, $args);
}
}
////////////////////////
function testimonials_list() {
if (is_page('9595')) {
$the_query = new WP_Query( array(
'post_type' => 'Testimonials'
) );
while ( $the_query->have_posts() ) :
$the_query->the_post();
print_r($the_query);
endwhile;
}
}
add_action('pre_get_posts','testimonials_list');