forked from kaziasifbillah/owncode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shortcode 2
50 lines (44 loc) · 1.35 KB
/
Shortcode 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
add_action( 'init', 'stock_theme_custom_post' );
function stock_theme_custom_post() {
register_post_type( 'testimonial',
array(
'labels' => array(
'name' => __( 'testimonials' ),
'singular_name' => __( 'testimonial' )
),
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'public' => false,
'show_ui' => true
)
);
}
function post_list_shortcode($atts){
extract( shortcode_atts( array(
'count' => '',
'type' => 'post'
), $atts) );
$q = new WP_Query(
array('
posts_per_page' => $count,
'post_type' => $type,
'orderby' => 'menu_order',
'order' => 'ASC')
);
$list = '<div class="custom_post_list">';
while($q->have_posts()) : $q->the_post();
$idd = get_the_ID();
$custom_field = get_post_meta($idd, 'custom_field', true);
$post_content = get_the_content();
$list .= '
<div class="single_post_item">
<h2>'.get_the_title().'</h2>
<p>'.get_the_content().'</p>
</div>
';
endwhile;
$list.= '</div>';
wp_reset_query();
return $list;
}
add_shortcode('testimonial', 'post_list_shortcode');
[testimonial type="testimonial"]