1

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.

3
  • 1
    If I understand it properly, you could try renaming your ACF field from subtitle to mt_post_subtitle and the get_post_meta() should continue to work.
    – Sally CJ
    Mar 31, 2020 at 10:03
  • 1
    @Sally CJ that worked. do you want to answer the question officially to take the credit for it? thanks so much.
    – RLM
    Mar 31, 2020 at 14:48
  • Glad it worked! And I've posted an answer. :)
    – Sally CJ
    Mar 31, 2020 at 22:12

1 Answer 1

1

First 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 ).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.