Replace my content by a custom field
-
Hello,
I got a problem, the function don’t go to the end… may be due to a big update (1300 posts) i don’t know.
Can you tell me what’s wrong ?
The function break all my custom post type… and the replace doesn’t work…add_action( 'get_header', 'my_update_posts' ); function my_update_posts() { if( ! isset( $_GET['update'] ) ) { //echo' error'; return; } $taxonomies = array( 'region', ); $args = array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); $terms_region = get_terms($taxonomies, $args); //var_dump($terms_departement); //die(); foreach( $terms_region as $term_region ) { $args = array( 'post_type' => 'visite', 'posts_per_page' => -1, 'post_status' => 'any', 'orderby' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'region', 'field' => 'slug', 'terms' => $term_region->slug, ) ), ); $posts = new wp_query( $args ); $posts = $posts->posts; //var_dump($posts); //exit; foreach( $posts as $post ) { //setup_postdata( $post ); //$value = $post->post_content; //var_dump($post); //die(); $value = get_post_meta( $post->ID, 'description_visit_factory', true ); if($value != ''){ //var_dump($value); //exit; wp_update_post( array( 'ID' => $post->ID, 'post_content' => $value, ) ); echo $post->post_title.' : ok ! <br/>'; //die(); } else { echo 'NO VALUE !!!'; } } echo '##### '.$term_region->name .' : done !<br/><br/>'; wp_reset_postdata(); } //die(); echo '###### update complete! #####'; die(); }
Thank you for help
Pop
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Replace my content by a custom field’ is closed to new replies.