如何仅将自定义元保存为评论数据,以便仅在“预览更改"中查看,而不在前端的实际帖子中保存 [英] How to save custom meta only for review data to see only in "Preview Changes", not the actual post in the front end

查看:86
本文介绍了如何仅将自定义元保存为评论数据,以便仅在“预览更改"中查看,而不在前端的实际帖子中保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加自定义元,并在预览更改"中查看.我可以看到更改,但更改也适用于前端的实际帖子.我希望将更改发布到发布预览"或单击预览更改"时不更新.请帮忙. 我已经关注了这个插件.

I am trying to add custom meta and see at "Preview Changes". I can see the changes but also changes apply to the actual post at Front end. I want the changes will update to the actual post when it Publish or Update not at "Preview Changes" click. Please help. I have followed this plugin.

function my_plugin_save_post($ post_id,$ post){

function my_plugin_save_post( $post_id, $post ) {

if ( $parent_id = wp_is_post_revision( $post_id ) ) {

    $parent  = get_post( $parent_id );
    $my_meta = get_post_meta( $parent->ID, 'my_meta', true );

    if ( false !== $my_meta )
          add_metadata( 'post', $post_id, 'my_meta', $my_meta );
}

} add_action('save_post','my_plugin_save_post');

} add_action( 'save_post', 'my_plugin_save_post' );

推荐答案

以下代码将阻止您的元数据保存在预览中,但是您将无法使用元数据预览发布的帖子.老实说,我想自己弄清楚这种情况:/

The following code will prevent your meta data from saving on preview but You won't be able to preview published posts with your metadata. Honestly I'm trying to figure out this situation myself :/

<?php // In your save metabox data function, near the top...
if (isset( $_POST['wp-preview'] ) && 'dopreview' == $_POST['wp-preview'] ) {
  if(get_post_status($post_id) == 'publish'){
    return; // This way we can still preview draft / scheduled posts
  }
}

老实说,我将使用此代码并将您的帖子简短地设置为draftprivate,同时进行编辑/预览,并在完成后按常规方式发布它们.

Honestly, I'd use this code and set your post briefly to draft or private while editing / previewing and publish them as normal when you're done.

这篇关于如何仅将自定义元保存为评论数据,以便仅在“预览更改"中查看,而不在前端的实际帖子中保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆