[英]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.