簡體   English   中英

Wordpress 中的 add_post_meta() function 的問題

[英]Problem with add_post_meta() function in Wordpress

當像這樣使用它時:

add_post_meta($post_ID, 'Name', "Bob", true );   

工作正常,但是當將字符串值存儲在變量中時,例如:

$name = "Bob";
add_post_meta($post_ID, 'Name', $name, true ); // <---- This doesn't work.

請幫忙。 謝謝。

試試下面的代碼。

$name = "Bob"; 
update_post_meta($post_ID, 'Name', $name );
$latestVideo = wp_get_recent_posts(array(
    'numberposts' => 1,
    'post_type'   =>'video',
    'post_status' => 'publish'
));

$latestVideoWeek = get_post_meta( $latestVideo[0]["ID"], "Week", true);
$latestVideoDate = get_post_meta( $latestVideo[0]["ID"], "Date", true);

function meta_info_video( $post_ID ) {
    add_post_meta( $post_ID, 'Semana', $latestVideoWeek, true );
    add_post_meta( $post_ID, 'Fecha', $latestVideoDate, true );
    add_post_meta( $post_ID, 'URL', '0', true  );
}

add_action( 'draft_video', 'meta_info_video' );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM