• Recently i had to change a theme in a site which had some custom fields, one particular custom field was used to link to a external url, in the new theme I also have a equivalent custom field, however the links from the old custom field are no longer accessible by the new theme… does that make sense?

    I would like to copy the data from that particular old custom field into the new custom field.

    With this plugin, would it be possible to copy content from a custom field into another custom field?

    Or does anyone know if there is another plugin out there that can do this already?

    https://www.ads-software.com/plugins/custom-content-shortcode/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Interesting question.. As I mentioned, this plugin only handles the displaying of content, so it doesn’t have a way to copy values from one custom field to another.

    Here is one possible solution. The newly created custom field needs to have exactly the same name as before, to access its content in the database.

    1) Activate the old theme.
    2) Install Custom Content Shortcode, and go to Dashboard -> Content. You should be able to find the exact name/slug of the custom field in question.
    3) Switch to the new theme.
    4) Using a plugin like Advanced Custom Fields, create a new field with the exact same name.

    The content of the custom field should then be accessible.

    That said, unless the theme is changed, it won’t know which field to display. So you’d have to display them using the [loop] and [content] shortcodes in the appropriate places. Alternatively, it is possible to search & replace in the theme files all occurrences of the field name to be exactly the same as the previous one..

    I’ve Googled to see if there’s a plugin that copies a field to another, and I didn’t find any. I think you may have come upon another common need which doesn’t yet have a simple solution. Please let me know if you make any progress with the above steps.

    Thread Starter delta123

    (@delta123)

    Hi,

    While not directly related to this questions, I just wanted to share some code I manage to put together that could be used to copy a value from a custom field, in this case the custom field is called: clpr_expire_date

    <?php
    $expiryDATE = get_post_meta(get_the_ID(), “clpr_expire_date”, true);
    echo ‘Expiry date : ‘.$expiryDATE;
    ?>
    Example Output>> Expiry date : 2014-12-31

    I guess with this code sample one could probably easily adapt it to write the value held in the variable to another custom field.

    Plugin Author Eliot Akira

    (@miyarakira)

    Hello, thank you for sharing this. Yes, I believe the steps would be:

    – Create a new custom field using a plugin like ACF.
    – Write a PHP loop that goes through all posts, and move the field values to the new custom field, using get/update/delete_post_meta.
    – Run the loop once.

    It would be nice if there was a plugin for general use, with a simple admin UI to select post type, old and new field names, and move/copy button. Perhaps it already exists somewhere..?

    Thread Starter delta123

    (@delta123)

    Eliot, I do have another query relating to the code above (but not related to the original scenario behind this post), I guess i’m potentially de-railing the thread, but maybe not, I’m wondering if you would know how to handle/code the following:

    Let me explain, to execute a [shortcode] in php, i believe it can be done like so:
    <?php
    echo do_shortcode(‘[shortcode]optional parameters[/shortcode]’);
    ?>

    So, in my case would look to pass an optional date parameter to my shortcode, like so:
    <?php
    echo do_shortcode(‘[myShortcode timetext=”2014-12-31″] Will be the expiry date![/myShortcode]’);
    ?>

    >> 2014-12-31 Will be the expiry date!
    (i know, the logic is not totally correct because is not an output, is simply to demonstrate that the parameter needs to take a date in that format)

    So, I been trying without success to pass the date value held in the variable to a shortcode, but cannot get it to work, do you happen to know how could i pass the value held in my variable to a shortcode? using the example code above do you happen to know how can i replace the shortcode date parameter with the actual variable?

    I was thinking something alone the following lines:
    <?php
    $expiryDATE = get_post_meta(get_the_ID(), “clpr_expire_date”, true);
    echo ‘Expiry date : ‘.$expiryDATE;
    echo do_shortcode(‘[myShortcode timetext=”.$expiryDATE.”] Will be the expiry date![/myShortcode]’);
    ?>

    My expected output then would be something along the following lines:

    Expiry date : 2014-12-31 Will be the expiry date!

    But the date value inside the shortcode seems to always be just zeros: 0000:00:00

    Do you have any precise tips as to how i may be able to resolve this?

    If you could crack this code I will share with you the cool end result which i’m miserably trying to implement.

    Thank you

    Plugin Author Eliot Akira

    (@miyarakira)

    Possibly it’s related to single and double quotes. Can you try this line?

    echo do_shortcode('[myShortcode timetext="'.$expiryDATE.'"] Will be the expiry date![/myShortcode]');

    The differences are the single quotes before and after the variable.

    Thread Starter delta123

    (@delta123)

    Thank you Elliot,

    Didn’t work but at least you have confirmed that I’m not that far off from a possible resolution.

    I will continue to try to find a solution and if i do i will come back here and updated this thread with my results.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to copy content of custom field into another custom field?’ is closed to new replies.