0
votes

I have several thousand posts in a custom post type called clothing which have a custom field called wpcf-translation

I need to insert a string into every single post's wpcf-translation custom field.

But I couldn't find anything on the internet. So my question is, is there an SQL query I can use to insert a string into every single post's custom field wpcf-translation in custom post type clothing?

Thanks

1
Is the wpcf-translation a 'serialized' field? Can you give an example of a row from that field? - josh.chavanne
I don't think the field is serialized. I'm really new to SQL queries, what sort of information are you looking for in the example row? - user2028856
I am fairly certain you are using the "Types" plugin to create your custom fields? From a cursory look I found that indeed many of the fields in Types are serialized data, you may find this post on the Wordpress Codex helpful - wordpress.org/support/topic/… - josh.chavanne
Yea I am using the Types plugin, so if the fields are serialized data, is there a query I can use to insert a string into these fields? - user2028856
Frankly I suggest using the Serialized Data Search and Replace for Wordpress if you don't know what serialized data is. Basically you will have to unserialize the data, and then reserialize it and then insert. Any direct db manipulation on those fields may be interpreted as 'corrupted' and not work. Serialized data means that every string or piece of data has a set length, and if that length is exceeded by the field's actual content it assumes it is corrupted. The script referred to can be found - interconnectit.com/products/… - josh.chavanne

1 Answers

1
votes

Based on your comment : I don't think the field is serialized. , the following should get the job done

$args = array(
            'post_type' => 'clothing',
            'posts_per_page' => -1,
        );

$query = new WP_Query( $args );

while( $query->have_posts() ) : if( $query->have_posts() ) : $query->the_post();
    update_post_meta($post->ID, 'wpcf-translation' , 'your string here');
else :
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
endif; 

endwhile;

wp_reset_postdata();

Ensure that you have a backup in place in case things go awry. Code created on the fly, so might need some fine tuning.