I am in the process of migrating posts from an existing wp site into a new wp site. The existing site has a custom field called subtitle
. When I import the blogs into the new site, I'd like populate my simple acf subtitle
text field with these hand coded custom fields.
What is the best way to do this?
Here is the code I've found in the existing sites single.php
that appears to be creating the sub title field:
$mt_post_subtitle = get_post_meta($post->ID, "mt_post_subtitle", true);
<?php echo esc_attr($mt_post_subtitle); ?>
Please let me know if I'm missing something and let me know what I can add to help solve this. Thanks in advance.
I am in the process of migrating posts from an existing wp site into a new wp site. The existing site has a custom field called subtitle
. When I import the blogs into the new site, I'd like populate my simple acf subtitle
text field with these hand coded custom fields.
What is the best way to do this?
Here is the code I've found in the existing sites single.php
that appears to be creating the sub title field:
$mt_post_subtitle = get_post_meta($post->ID, "mt_post_subtitle", true);
<?php echo esc_attr($mt_post_subtitle); ?>
Please let me know if I'm missing something and let me know what I can add to help solve this. Thanks in advance.
Share Improve this question asked Mar 31, 2020 at 3:04 RLMRLM 2475 silver badges19 bronze badges 3 |1 Answer
Reset to default 1First off, you should know that get_post_meta()
doesn't create any custom fields (or metadata), it only retrieves the custom field's value. But the WordPress functions that do create custom fields (for posts) are add_post_meta()
and update_post_meta()
.
So that get_post_meta($post->ID, "mt_post_subtitle", true)
simply retrieves the value of the meta/field named mt_post_subtitle
for the post (referenced by that $post
) and as I mentioned in the comment, you could try renaming the ACF field from subtitle
to mt_post_subtitle
and the get_post_meta()
call in your single.php
(single post) template should continue to work normally.
Alternatively, you could've also used the ACF function for retrieving custom field's value, which is get_field()
, but renaming the field name is an easier option in that no code changes needed. :) But for reference, with get_field()
and without changing the ACF field name, you'd change that get_post_meta()
to get_field( 'subtitle', $post->ID )
.
subtitle
tomt_post_subtitle
and theget_post_meta()
should continue to work. – Sally CJ Commented Mar 31, 2020 at 10:03