How i can save in Subtitle (mysql field) from my own plugin?

Posted in: Newspaper
Post count: 45

Hello, i need create a script for import a lot of news, and i am needing to discover how is the way to insert the subtitle (i think this is a custom field).
For example:


$new_post = array(
'post_title' => utf8_encode($tituloTxt),
'post_content' => utf8_encode($textoTxt),
'post_excerpt' => utf8_encode($pretituloTxt),
'post_subtitle' => utf8_encode($subtituloTxt),
'post_date' => date('Y-m-d H:i:s'),
'post_date_gmt' => date('Y-m-d H:i:s'),
'post_type' => 'post',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_category' => array($seccionID),
'tags_input' => array(136)
);
$insertar_noticia_ID = @wp_insert_post( $new_post );

Of course, “post_subtitle” doesn’t exists!! it’s only for the example purpose.
Excuse me for my bad English!!

Best regards.

Post count: 7909

Hi,

The subtitle field key is td_subtitlehttp://screencast.com/t/sTCueS1z if this is what you need.

Thanks!

Post count: 45

if I insert the metadata, the field “subtitle” fill with an empty value. But the field is added like an extra custom field. You can see this in the picture.

This is my code,

add_post_meta( $insertar_noticia_ID, 'td_subtitle', utf8_encode($pretituloTxt) );

And this is de result:
Here you can see the empty value of subtitule

Are you forgetting something?

Thanks!.

Post count: 7909

Hi,

I’m not sure what you are trying to do, the theme comes already with subtitle that is saved in the post meta. I see that you have added it in custom fields.
Do you want to display it somewhere? Please provide more details.

Thanks!

Post count: 45

Hi,

Like you say, The subtitle field key is td_subtitle.
If I want to fill this field from a plugin to import news, i do this:


add_post_meta( $ID_post, 'td_subtitle', "Hola Mundo." );

But, the field doesn’t fill. This appear empty; and you can see a new custom field called “td_subtitle” too.

The question is: What command function i must use to import in the td_subtitle custom field theme.

You follow me?

Post count: 1291

Hi,

Try using the update_post_meta() function – https://codex.wordpress.org/Function_Reference/update_post_meta – , the theme displays the subtitle on posts, this is the code which retrives the data – http://screencast.com/t/VpclbtzJxLhttp://screencast.com/t/njx8YOoC
You should also make a condition to check if it’s already set.

Thank you!

Post count: 45

Hi Emil, thank you for your answer. I need to save “td_subtitle” inside the array “td_post_theme_settings”.

What is the syntax using update_post_meta() function?.

Thank you.

Post count: 1291

Hi,

The syntax is described in the official documentation – https://codex.wordpress.org/Function_Reference/update_post_meta
Try the following code: – http://screencast.com/t/B88Se5VOc

// save from td_subtitle to td_post_theme_settings->td_subtitle
$td_subtitle = array('td_subtitle' => get_post_meta($post_id, 'td_subtitle', true));
if ($td_subtitle != '') {
update_post_meta($post_id, 'td_post_theme_settings', $td_subtitle);
}

Thank you!

  • This reply was modified 11 years by Emil G.
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic.