Forums

Batch copy of fields (4 posts)

  1. kennefu
    Member
    Posted 1 year ago #

    I couldn't find a plug-in, so I assume this must be done by SQL.

    What I want to do for every post is copy the post_content value into a custom field Value I created for the same post.

    One thing to note is that post_content is in a wp_posts table, and the custom field value is in the wp_postmeta table. So two different tables.

    Thanks in advance. Having been looking for a solution for a long time.

  2. vtxyzzy
    Member
    Posted 1 year ago #

    Please explain further. Do you want the entire content of the post copied? Do you want this for only existing posts, or as each new post is created? Can you give an example? Do you have a link to your site where the posts can be seen?

  3. kennefu
    Member
    Posted 1 year ago #

    Hi vtxyzzy,

    Thanks for the reply. I figured it out using php. I wanted to copy from existing posts. From the wordpress default fields to the custom fields. Eg. from publish date value to my custom field's date field

    Here is the code:

    <?php query_posts("showposts=-1&offset=0&category_name=audio"); ?>
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<?php update_post_meta(get_the_ID(), 'date', get_the_time('Y-m-d H:i:s')); ?>
    	<?php update_post_meta(get_the_ID(), 'audio_url', get_the_content()); ?>
    	<?php update_post_meta(get_the_ID(), 'speaker', get_the_author()); ?>
    
    	<?php endwhile; ?>
    	<?php endif; ?>
    <?php wp_reset_query(); ?>
  4. vtxyzzy
    Member
    Posted 1 year ago #

    Glad you got it working.

Topic Closed

This topic has been closed to new replies.

About this Topic