简体   繁体   English

Wordpress 数据库:将自定义字段的值添加到帖子开头(并合并保存)

[英]Wordpress database: add value of custom field to beginning of post (and save it combined)

I need to get the value of a custom field ( _subtitle ) from the post meta and have it saved to the beginning of the post text (post_content).我需要从帖子元中获取自定义字段 ( _subtitle ) 的值,并将其保存到帖子文本 (post_content) 的开头。

How can I achieve this?我怎样才能做到这一点? (I tried the update() function but lost the post content before) (我尝试了update()功能,但之前丢失了帖子内容)

You need to use get_post_meta() it might look something like that if you want to place it within a template.您需要使用get_post_meta()如果您想将其放置在模板中,它可能看起来像这样。

<?php
    $subs = get_post_meta(get_the_ID(),'_subtitle',true);

    $post_content = get_the_content();

    echo $subs.$post_content;
?>

This would be the gist of it, you could also filter the_content();这将是它的要点,你也可以过滤the_content(); and place the code within the functions.php并将代码放在functions.php中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM