繁体   English   中英

在 Wordpress 中为新帖子(使用自定义帖子类型)预填内容、标题和自定义字段

[英]Pre-fill content, title and custom fields to new posts (with custom post-type) in Wordpress

每次我在 Wordpress 管理面板中按 ADD NEW 时,有没有办法预先填写新帖子(使用特定的自定义帖子类型)?

因为现在我使用带有预填充内容的帖子,每次我需要添加新帖子时,我都会复制这个旧帖子。 但这并不像按添加新并预先填充所有内容那么快。

也许有一种方法可以在我按下 ADD NEW 后立即填充我想要的所有内容(文本、选择框、自定义字段...)? 甚至在自定义字段中填写 POST_ID。

我尝试使用这个,但我只能填写自定义字段,也许有人可以帮助我扩大其限制并填写所有帖子:D。

function my_editor_content( $content, $post ) {
if ($post->post_type == property) {
$content = 'your content';
        }
        return $content;
    }

我什至使用这个来简化,但我每次都需要复制并粘贴相同的代码。 而且我不知道如何填充自定义字段以及如何选择自定义分类法。

add_filter( 'default_title', 'my_editor_title' );
function my_editor_title( $title ){
    $title = 'Default Title';
    return $title;
}

如果我理解正确。 查看这些过滤器钩子 wp_insert_post_data functions.php

 if (isAdmin()){

    add_filter('wp_insert_post_data','custom_insert_post', '99', 2);

    function custom_insert_post($data, $postarr){ <-- 
        $data['post_title'] = 'default_post_title';
        $data['post_status'] = 'future'; 
        //.... etc            


    }


 }

也看看那个钩子 - save_post

 add_action('save_post', 'custom_insert_meta_values');

 function custom_insert_meta_values($post_ID){
   $default_meta_key = '....';
   $default_meta_value = '....';

   add_post_meta($post_ID, $default_meta_key, $default_meta_value);
 }

暂无
暂无

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

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