Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress:自定义字段现在在Wordpress外部添加时显示_Php_Wordpress_Custom Fields - Fatal编程技术网

Php Wordpress:自定义字段现在在Wordpress外部添加时显示

Php Wordpress:自定义字段现在在Wordpress外部添加时显示,php,wordpress,custom-fields,Php,Wordpress,Custom Fields,我有一个要求,需要我从Wordpress之外创建一些自定义字段的帖子 我已经能够添加后,必要的自定义字段从外部使用标准的WP功能 我还可以在Posteta和posts表中看到条目 但是,这些值在我要显示它们的前端不可用。 但是,当我在仪表板的“写入”面板中打开这篇文章时,我看到所有值都已正确填充,如果我只是更新它,这些值就会开始出现在前端 我肯定我错过了一些东西。因此,非常感谢您的帮助 下面是我目前用来实现上述目标的代码 $post = array( 'post_name' =&

我有一个要求,需要我从Wordpress之外创建一些自定义字段的帖子

我已经能够添加后,必要的自定义字段从外部使用标准的WP功能

我还可以在Posteta和posts表中看到条目

但是,这些值在我要显示它们的前端不可用。 但是,当我在仪表板的“写入”面板中打开这篇文章时,我看到所有值都已正确填充,如果我只是更新它,这些值就会开始出现在前端

我肯定我错过了一些东西。因此,非常感谢您的帮助

下面是我目前用来实现上述目标的代码

$post = array(

  'post_name'      => 'g-test-3', // The name (slug) for your post
  'post_title'     => 'G Testing 3', // The title of your post.
  'post_status'    => 'publish', // Default 'draft'.
  'post_type'      =>  'post',// Default 'post'.
  'post_author'    =>  5090,// The user ID number of the author. Default is the current user ID.
  'post_excerpt'   => '', // For all your post excerpt needs.
  'post_date'      =>  date('Y-m-d H:i:s'),  // The time post was made.
  'comment_status' => 'open', // Default is the option 'default_comment_status', or 'closed'.
  'post_category'  => array(644)// Default empty.
);  

$posted =  wp_insert_post( $post, true );
echo 'post id: '. $posted;
$added = array();
$added[]= update_post_meta($posted, 'external_url', 'http://example.com/external-url', false);
$added[]= update_post_meta($posted, 'media', 'Yes', false);
$added[]= update_post_meta($posted, 'remarks', 'These are the example remarks', false);
$added[]= update_post_meta($posted, 'alternate_headline', 'Alternate headline for G Testing', false);
$added[]= update_post_meta($posted, '_mf_write_panel_id', '13', false);

在wordpress之外添加是什么意思?我没有使用常规的WP管理员。我正在调用WP外部的函数来创建这些条目。