douxia1988 2014-12-11 18:42
浏览 32

无法通过WordPress插件中的短代码显示自定义帖子元

I've created a plugin that sets up a custom post type ('Programmes'), taxonomy and a short code to display the custom posts. I'm trying to display a custom post meta field (Broadcast Date) via the shortcode. These are the methods I've tried so far:

This is the method I'd have preferred as it allows me to use it for multiple meta values:

if ( $query->have_posts() ) { ?>
    <div class="schedule-container">
        <?php while ( $query->have_posts() ) : $query->the_post();
        $programmeImage = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );           
        $programmeMeta = get_post_meta($post->ID,'_meta_content',TRUE);
        ?>
        <div id="programme-<?php the_ID(); ?>" <?php post_class(); ?> style="background-image: url( <?php echo $programmeImage ?> )">
            <div class="schedule-titlebar">
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <p><?php echo $programmeMeta['broadcast-date'] ?></p>
            </div>
        </div>
        <?php endwhile;
        wp_reset_postdata(); ?>
    </ul>
}

But that didn't work so I tried this instead:

if ( $query->have_posts() ) { ?>
    <div class="schedule-container">
        <?php while ( $query->have_posts() ) : $query->the_post();
        $programmeImage = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );           
        $programmeBroadcastDate = get_post_meta($post->ID,'broadcast-date',TRUE);
        ?>
        <div id="programme-<?php the_ID(); ?>" <?php post_class(); ?> style="background-image: url( <?php echo $programmeImage ?> )">
            <div class="schedule-titlebar">
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                <p><?php echo $programmeBroadcastDate ?></p>
            </div>
        </div>
        <?php endwhile;
        wp_reset_postdata(); ?>
    </ul>
}

and that doesn't work either!

Any ideas? Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法