admin管理员组文章数量:1431391
I want to bulk append my custom field named 'LINK' (with data like '') to the end of the post content, so I can go back to using a standard theme with no support for custom fields.
Apparently this answer to the question 'Bulk move (or copy) from a custom field to the post content?' is what I need, except it replaces the whole post-content instead of appending to it.
Can somebody help me changing this code to append to the post content?
add_shortcode('update-posts-from-custom-fields', 'upfc_fields321');
function upfc_fields321() {
$args = array(
'meta_key' => 'custom_field',
'meta_query' => array(
array(
'key' => 'custom_field',
'value' => '',
'compare' => '!=',
),
),
'post_count' => '-1'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$post_counter = $save_counter = $delete_counter = 0;
while ( $the_query->have_posts() ) {
$the_query->the_post();
global $post; // not sure if this is needed, but it can't hurt
echo '
<div style="position: relative;">
<h3 style="display: block;">' .
the_title() . '
</h3>
<div style="width: 48%; display: inline-block; float: none;">' .
the_content() .
'</div>';
$post_counter++;
$post->post_content = get_post_meta($post->ID, 'custom_field', true);
$post->post_content_filtered = '';
$post->post_excerpt = '';
// uncomment next line when you are ready to commit changes
// wp_update_post($post); $save_counter++;
// uncomment next line if you want to delete the meta key (useful if you have too many posts and want to do them in batchces)
// delete_post_meta($post->id, 'custom_field'); $delete_counter++;
echo '
<div style="width: 48%; display: inline-block; float: none">' .
the_content() .
'</div>
</div>';
}
} else {
// no posts found
};
echo
'<hr>Processed posts: ' . $post_counter .
'<hr>Saved posts:' . $save_counter .
'<hr>Deleted meta from: ' . $delete_counter . ' posts';
wp_reset_postdata() ;
}
本文标签: Bulk append custom field to post content
版权声明:本文标题:Bulk append custom field to post content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745573094a2664166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论