ecv86
ecv86

Reputation: 1

Problem with add_post_meta() function in Wordpress

When a use it like this:

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

works fine, but when a store an string value inside a variable, for example:

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

Some help please. Thanks.

Upvotes: 0

Views: 364

Answers (2)

ecv86
ecv86

Reputation: 1

$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' );

Upvotes: 0

Bhautik
Bhautik

Reputation: 11282

Try the below code.

$name = "Bob"; 
update_post_meta($post_ID, 'Name', $name );

Upvotes: 0

Related Questions