这段代码将进入我正在创建的一个示例插件中,作为使用CPT的测试,并将它们打印到页面上。
我一直在尝试让print\\u r()给我一个对象。自定义过帐类型已过帐验证。数据存储在MySQL中-已验证。因此,post类型正在注册。
请为我提供一双新眼睛,告诉我在查询中缺少什么。
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\');