【问题标题】:Appending Post Meta to Beginning of Post Content将帖子元附加到帖子内容的开头
【发布时间】:2017-03-13 06:41:41
【问题描述】:

我正在尝试将 Publish 的行为更改为 Apple New Wordpress plugin。我的主题使用自定义字段来嵌入视频,但插件无法识别该内容。我正在尝试将元数据附加到 Apple News 帖子的开头。这是我的代码不起作用:

function add_post_meta_content($content) {
 $meta = get_post_meta( get_the_ID(), 'csco_post_embed', true );
 return .$meta.$content;
}
add_filter('apple_news_exporter_content_pre', add_post_meta_content);

apply_filters( 'apple_news_exporter_content_pre', $post->post_content, $post->ID );

例如,如果我将代码更改为以下内容:

function add_post_meta_content($content) {
 $meta = get_post_meta( get_the_ID(), 'csco_post_embed', true );
 return 'Print this content before the post'.$meta.$content;
}
add_filter('apple_news_exporter_content_pre', add_post_meta_content);

apply_filters( 'apple_news_exporter_content_pre', $post->post_content, $post->ID );

它将“在帖子之前打印此内容”附加到帖子的开头而不会出现问题。我在这里想念什么?

【问题讨论】:

标签: php wordpress


【解决方案1】:

插件已经将$post->ID 发送到您的过滤器,因此无需调用get_the_ID()

试试这个代码:

function add_post_meta_content($content, $post_id) {
    $meta = get_post_meta( $post_id, 'csco_post_embed', true );
    return 'Print this content before the post'.$meta.$content;
}
add_filter('apple_news_exporter_content_pre', add_post_meta_content, 10, 2);

--

如果这不起作用,请确保您确实在csco_post_embed 键下的数据库元表中保存了一些内容。确认这一点的简单方法是打开您的数据库并进行快速查询:

SELECT *
FROM wp_postmeta
WHERE post_id = ENTER_YOUR_POST_ID_HERE AND meta_key = 'csco_post_embed';

【讨论】:

    【解决方案2】:

    太棒了!你让我成功了 99%。必须退回 oembed 才能使视频正常工作。这是最终代码,以防其他人来查看。

    function add_post_meta_content($content, $post_id) {
        $meta = wp_oembed_get( get_post_meta( $post_id, 'csco_post_embed', true ) );
        return $meta.$content;
    }
    add_filter('apple_news_exporter_content_pre', add_post_meta_content, 10, 2);

    【讨论】:

      猜你喜欢
      • 2013-05-28
      • 1970-01-01
      • 2015-05-06
      • 2012-10-06
      • 2011-11-27
      • 2013-01-12
      • 2020-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多