[英]WP How to display a field with a list of all assigned posts of this category in the admin panel of a category?
[英]How to display a list of posts in WP with meta information
在 WP 站点中,我试图设置一个事件页面。 我已经设置了自定义帖子类型并使用 metabox.io 插件定义了一个元框。 metabox 包含一个 ID 为“date_1”的日期选择器。 我现在试图找到一种方法来显示带有事件日期和标题的帖子列表。 标题工作正常,但我无法显示日期。
线
$events .= '<a href="'. get_permalink() .'">' . get_post_meta(get_the_ID(), 'date_1', true) . " - " . get_the_title() .'</a>';
返回标题,但不返回日期。 如果我将 get_post_meta 行包装在 print_r 中,它将返回 1。
我也尝试过:
$events .= '<a href="'. get_permalink() .'">' . get_post_meta($post->ID, $field['date_1'], TRUE ). " - " . get_the_title() .'</a>';
但这返回“数组”而不是一个。
完整代码
if ( ! function_exists('events_shortcode') ) {
function events_shortcode() {
$args = array(
'post_type' => 'kalender',
'post_status' => 'publish',
'order' => 'ASC',
'posts_per_page' => 10,
);
$postslist = new WP_Query( $args );
global $post;
if ( $postslist->have_posts() ) :
$events .= '<div class="events-lists">';
while ( $postslist->have_posts() ) : $postslist->the_post();
$events .= '<div class="items">';
$events .= '<a href="'. get_permalink() .'">' . get_post_meta(get_the_ID(), 'date_1', true) . " - " . get_the_title() .'</a>';
$events .= '</div>';
endwhile;
wp_reset_postdata();
$events .= '</div>';
endif;
return $events;
}
add_shortcode( 'events', 'events_shortcode' );
}
请阅读 metabox.io 插件日期字段文档。
我希望你能解决你的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.